Skip to content

Instantly share code, notes, and snippets.

@u1735067
Created July 6, 2021 10:48
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 u1735067/fa4511befdb6cf4bd34de3d58bca5dad to your computer and use it in GitHub Desktop.
Save u1735067/fa4511befdb6cf4bd34de3d58bca5dad to your computer and use it in GitHub Desktop.
Why ?
---
# ---Setup:
# > ansible-playbook -i mytest.ini mytest.yml --limit test2
# ./mytest.ini:
# test1 site=ams
# test2 site=ams
# test3 site=blg
#
# ---Result:
# PLAY [TEST] ********************************************************************
#
# TASK [ansible.builtin.debug] ***************************************************
# fatal: [test2]: FAILED! => {"msg": "'my_host' is undefined"}
#
# NO MORE HOSTS LEFT *************************************************************
#
# PLAY RECAP *********************************************************************
# test2 : ok=0 changed=0 unreachable=0 failed=1
# skipped=0 rescued=0 ignored=0
- name: TEST
hosts: all
connection: local
vars:
ansible_connection: local
run_once: true
tasks:
- ansible.builtin.debug:
msg: "{{ my_host }}"
vars:
ansible_connection: ansible.netcommon.httpapi
ansible_host: "{{ my_host }}"
ansible_httpapi_host: "{{ my_host }}"
loop_control:
loop_var: my_host
label: "{{ my_host }}"
loop: "{{ hostvars.values() | map(attribute='inventory_hostname') }}"
delegate_to: localhost
# delegate_facts: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment