unify local and remote mode of operation

This commit is contained in:
Glenn K. Lockwood
2020-07-27 20:43:34 -07:00
parent 621dd3feb4
commit 36a0a9996d
8 changed files with 143 additions and 106 deletions
+27 -11
View File
@@ -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