Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@raags
Created May 9, 2015 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raags/0f2089ec1208617b86d8 to your computer and use it in GitHub Desktop.
Save raags/0f2089ec1208617b86d8 to your computer and use it in GitHub Desktop.
Ansible append an existing list using set_fact
---
- name: Set facts on all nodes
hosts: "{{cli_hosts}}"
gather_facts: false
tasks:
- name: determine current target
stat: path=/etc/current
register: current_link
- set_fact:
target: "{{ current_link.stat.lnk_source|basename }}"
- debug: var=target
- name: Loop through facts and process them
hosts: localhost
gather_facts: false
tasks:
- command: mktemp
register: temp_file
- template: src=targets.yml.j2 dest="{{ temp_file.stdout }}"
- include_vars: "{{ temp_file.stdout }}"
- file: path="{{ temp_file.stdout }}" state=absent
- debug: var=final_targets
---
final_targets:
{% for host in hostvars %}
{% if 'target' in hostvars[host] %}
- {{ hostvars[host]['target'] }}
{% endif %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment