update to work in local mode

master
Glenn K. Lockwood 4 years ago
parent 36a0a9996d
commit 0c2dbd7063
  1. 39
      roles/common/tasks/loadconfig.yml
  2. 45
      roles/common/tasks/main.yml

@ -0,0 +1,39 @@
---
# 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: load raspberry pi configuration (local mode)
include_vars:
file: "../../../host_vars/{{ macaddrs[my_macaddr] }}"
name: myconfig
when: inventory_hostname_short == 'localhost'
tags:
- raspi
- sw
- sshd
- motd
- name: load raspberry pi configuration (remote mode)
set_fact:
myconfig: "{{ hostvars[inventory_hostname_short] }}"
when: "inventory_hostname_short != 'localhost'"
tags:
- raspi
- sw
- sshd
- motd
- debug:
msg: "loaded configuration for {{ myconfig.hostname }}"
- assert:
that: "{{ myconfig|length > 0 }}"

@ -1,48 +1,5 @@
---
# 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: self-identify based on mac address (local mode)
set_fact:
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
- sshd
- motd
- name: store system configuration
set_fact:
myconfig: "{{ hostvars[myhostname] }}"
tags:
- raspi
- sw
- sshd
- motd
- debug:
var: myconfig
- include: loadconfig.yml
# Gather facts specific to the Raspberry Pi platform
- include: raspi-facts.yml

Loading…
Cancel
Save