Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save electrofelix/3c2e7c2917b968e928fa to your computer and use it in GitHub Desktop.

Select an option

Save electrofelix/3c2e7c2917b968e928fa to your computer and use it in GitHub Desktop.
- hosts: localhost
connection: local
tasks:
- name: setup parallel workers
add_host:
name: task-{{ item }}
groups: parallel
service: "{{ item }}"
always_run: yes
with_items:
- one
- two
- three
- hosts: parallel
connection: local
tasks:
- name: build data
set_fact: var={{ hostvars[item].service }}
delegate_to: localhost
run_once: yes
register: services
with_items: groups['parallel']
- debug: var=services
delegate_to: localhost
run_once: yes
@electrofelix
Copy link
Author

last task produces:

ok: [task-one -> localhost] => {
    "services": {
        "changed": false, 
        "msg": "All items completed", 
        "results": [
            {
                "ansible_facts": {
                    "var": "one"
                }, 
                "invocation": {
                    "module_args": "var=one", 
                    "module_name": "set_fact"
                }, 
                "item": "task-one"
            }, 
            {
                "ansible_facts": {
                    "var": "two"
                }, 
                "invocation": {
                    "module_args": "var=two", 
                    "module_name": "set_fact"
                }, 
                "item": "task-two"
            }, 
            {
                "ansible_facts": {
                    "var": "three"
                }, 
                "invocation": {
                    "module_args": "var=three", 
                    "module_name": "set_fact"
                }, 
                "item": "task-three"
            }
        ]
    }
}

Which I can then use map on to extract ansible_facts.var which is the piece I'm interested in.

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