Skip to content

Instantly share code, notes, and snippets.

@Znuff
Created May 8, 2017 16:30
Show Gist options
  • Save Znuff/feeaa7459df445b306de28a7d3dcd05e to your computer and use it in GitHub Desktop.
Save Znuff/feeaa7459df445b306de28a7d3dcd05e to your computer and use it in GitHub Desktop.
node# cat myuuid.fact
"e48aeb68-ebb7-4e53-971d-0b4b59d242c4"
---
master# ansible cloudini-hosts -m setup -a "filter=ansible_local"
bu-x40092.appnor.net | SUCCESS => {
"ansible_facts": {
"ansible_local": {
"myuuid": "e48aeb68-ebb7-4e53-971d-0b4b59d242c4"
}
},
"changed": false
}
---
- name: uuidgen for libvirtd config
hosts: cloudini-hosts
gather_facts: True
# facts.d will automatically be read, so that myuuidgen will be populated if it is defined
tasks:
- name: create directory for ansible custom facts
file: state=directory recurse=yes path=/etc/ansible/facts.d
- name: run uuidgen if necessary
shell: uuidgen
register: uuidgen
when: myuuid is not defined
- name: save to facts
set_fact:
myuuid: "{{ uuidgen.stdout }}"
when: myuuid is not defined
- name: save to facts.d
template:
src: templates/uuid_template.j2
dest: /etc/ansible/facts.d/myuuid.fact
force: False
- name: re-read facts
setup: filter=ansible_local
- name: configure libvirtd.conf with myuuid
template:
src: templates/libvirtd.conf.j2
dest: /etc/libvirt/libvirtd.conf
force: True
{{ myuuid | to_nice_json }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment