Skip to content

Instantly share code, notes, and snippets.

@nikuyoshi
Last active August 12, 2018 13:54
Show Gist options
  • Save nikuyoshi/203f6eafd7e86db697ce446e2bbd2789 to your computer and use it in GitHub Desktop.
Save nikuyoshi/203f6eafd7e86db697ce446e2bbd2789 to your computer and use it in GitHub Desktop.
Ansible Playbook for setting sequential path in the set_fact
TASK [debug] **************************************************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"instance_path_list": [
"/var/log/instance_1/log",
"/var/log/instance_2/log",
"/var/log/instance_3/log",
"/var/log/instance_4/log"
]
}
- name: Set fatcs
hosts: localhost
sudo: no
connection: local
vars:
instance_number: 4
tasks:
- name: Register instance's sequential path
set_fact:
instance_path: /var/log/instance_{{ item }}/log
with_sequence: start=1 end={{ instance_number }}
register: sequential_path
- name: Set fact
set_fact:
instance_path_list:
"{{ sequential_path.results | map(attribute='ansible_facts.instance_path') | list }}"
- name: debug
debug:
var: instance_path_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment