Skip to content

Instantly share code, notes, and snippets.

@lanky
Last active September 7, 2016 16:41
Show Gist options
  • Save lanky/878c41af4aee90769541d5ef4cb39900 to your computer and use it in GitHub Desktop.
Save lanky/878c41af4aee90769541d5ef4cb39900 to your computer and use it in GitHub Desktop.
---
- name: create a list and use it for something
hosts: all
vars:
ip_list: []
gather_facts: no
tasks:
- name: loop over hosts and create list of IP:PORT entries
set_fact:
ip_list: "{{ ip_list }} + [ '{{ '%s:6379' | format(item) }}' ]"
with_items: "{{ groups['tag_Deployment_asdf_redis_pc'] }}"
delegate_to: localhost
run_once: yes
- name: use list for something
debug:
msg: "source /etc/profile; echo yes | redis-trib.rb create --replicas 0 {{ip_list|join(',')}}"
run_once: yes
@lanky
Copy link
Author

lanky commented Sep 7, 2016

[lanky@ultra ansibletests]$ ansible --version
ansible 2.1.1.0
config file = /home/lanky/Documents/dev/ansibletests/ansible.cfg
configured module search path = Default w/o overrides

inventory:

localhost ansible_connection=local

[tag_Deployment_asdf_redis_pc]
172.28.96.224
172.28.96.225

output:

PLAY [create a list and use it for something] **********************************

TASK [loop over hosts and create list of IP:PORT entries] **********************
ok: [localhost -> localhost] => (item=172.28.96.224) => {"ansible_facts": {"ip_list": ["172.28.96.224:6379"]}, "changed": false, "item": "172.28.96.224"}
ok: [localhost -> localhost] => (item=172.28.96.225) => {"ansible_facts": {"ip_list": ["172.28.96.224:6379", "172.28.96.225:6379"]}, "changed": false, "item": "172.28.96.225"}

TASK [use list for something] **************************************************
ok: [localhost] => {
    "msg": "source /etc/profile; echo yes | redis-trib.rb create --replicas 0 172.28.96.224:6379,172.28.96.225:6379"
}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0   

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment