Created
May 9, 2015 16:31
-
-
Save raags/0f2089ec1208617b86d8 to your computer and use it in GitHub Desktop.
Ansible append an existing list using set_fact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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