Skip to content

Instantly share code, notes, and snippets.

@richm
Created June 30, 2021 19:36
Show Gist options
  • Save richm/e9d338d8b39254b84b90fd2bf0b0b0a1 to your computer and use it in GitHub Desktop.
Save richm/e9d338d8b39254b84b90fd2bf0b0b0a1 to your computer and use it in GitHub Desktop.
test playbook test_import_include.yml:
- hosts: localhost
gather_facts: false
vars:
interface: test_interface
test_import_include:
- name: "{{ interface }}"
state: up
type: ethernet
ip:
dhcp4: "no"
auto6: "no"
tasks:
- name: before include_role
debug:
msg: before include_role
- include_role:
name: test_import_include
- name: before import_role
debug:
msg: before import_role
- import_role:
name: test_import_include
- name: end
debug:
msg: end
test role in roles/test_import_include/tasks/main.yml
- name: show the var
debug:
msg: test_import_include {{ test_import_include | to_nice_json }}
run it like this:
ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook -vv test_import_include.yml
output:
PLAY [localhost] ***************************************************************************
META: ran handlers
TASK [before include_role] *****************************************************************
task path: /home/rmeggins/ansible_sandbox/test_import_include.yml:13
ok: [localhost] => {}
MSG:
before include_role
TASK [include_role : test_import_include] **************************************************
task path: /home/rmeggins/ansible_sandbox/test_import_include.yml:16
TASK [test_import_include : show the var] **************************************************
task path: /home/rmeggins/ansible_sandbox/roles/test_import_include/tasks/main.yml:1
ok: [localhost] => {}
MSG:
test_import_include [
{
"ip": {
"auto6": "no",
"dhcp4": "no"
},
"name": "test_interface",
"state": "up",
"type": "ethernet"
}
]
TASK [before import_role] ******************************************************************
task path: /home/rmeggins/ansible_sandbox/test_import_include.yml:18
ok: [localhost] => {}
MSG:
before import_role
TASK [test_import_include : show the var] **************************************************
task path: /home/rmeggins/ansible_sandbox/roles/test_import_include/tasks/main.yml:1
ok: [localhost] => {}
MSG:
test_import_include [
{
"ip": {
"auto6": "no",
"dhcp4": "no"
},
"name": "test_interface",
"state": "up",
"type": "ethernet"
}
]
TASK [end] *********************************************************************************
task path: /home/rmeggins/ansible_sandbox/test_import_include.yml:23
ok: [localhost] => {}
MSG:
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment