mirror of
https://github.com/ruanbekker/rpi-ansible.git
synced 2026-09-05 05:50:41 +02:00
unify local and remote mode of operation
This commit is contained in:
+27
-11
@@ -1,22 +1,31 @@
|
||||
---
|
||||
|
||||
# Gather facts specific to the Raspberry Pi platform
|
||||
- include: raspi-facts.yml
|
||||
- include: linux-facts.yml
|
||||
|
||||
# Basic hostname setup
|
||||
- name: Get MAC address
|
||||
debug:
|
||||
msg: "{{ hostvars[inventory_hostname].ansible_eth0.macaddress }}"
|
||||
# Self identify and load config - this allows the playbook to run on either
|
||||
# localhost or a remote host
|
||||
- name: store MAC address for eth0
|
||||
set_fact:
|
||||
my_macaddr: "{{ hostvars[inventory_hostname].ansible_eth0.macaddress }}"
|
||||
when: inventory_hostname == 'localhost'
|
||||
tags:
|
||||
- raspi
|
||||
- sw
|
||||
- sshd
|
||||
- motd
|
||||
|
||||
- name: store MAC address
|
||||
- name: self-identify based on mac address (local mode)
|
||||
set_fact:
|
||||
my_macaddr: "{{ hostvars[inventory_hostname].ansible_eth0.macaddress }}"
|
||||
myhostname: "{{ macaddrs[my_macaddr] }}"
|
||||
when: inventory_hostname_short == 'localhost'
|
||||
tags:
|
||||
- raspi
|
||||
- sw
|
||||
- sshd
|
||||
- motd
|
||||
|
||||
- name: self-identify based on mac address (remote mode)
|
||||
set_fact:
|
||||
myhostname: "{{ inventory_hostname_short }}"
|
||||
when: "inventory_hostname_short != 'localhost'"
|
||||
tags:
|
||||
- raspi
|
||||
- sw
|
||||
@@ -25,13 +34,20 @@
|
||||
|
||||
- name: store system configuration
|
||||
set_fact:
|
||||
myconfig: "{{ macaddrs[my_macaddr] }}"
|
||||
myconfig: "{{ hostvars[myhostname] }}"
|
||||
tags:
|
||||
- raspi
|
||||
- sw
|
||||
- sshd
|
||||
- motd
|
||||
|
||||
- debug:
|
||||
var: myconfig
|
||||
|
||||
# Gather facts specific to the Raspberry Pi platform
|
||||
- include: raspi-facts.yml
|
||||
- include: linux-facts.yml
|
||||
|
||||
- name: set hostname
|
||||
shell: "raspi-config nonint do_hostname {{ myconfig.hostname }}"
|
||||
when: raspi_hostname != myconfig.hostname
|
||||
|
||||
Reference in New Issue
Block a user