Thank you for the response. The problem is that the tag name is itself a variable.
Two playbooks and a role:
import_playbook_B.yml
---
- hosts: localhost
gather_facts: false
vars:
tasks:
- block:
- debug:
msg: "import_playbook_B.yml: including tasks C"
- include_tasks: include_playbook_C.yml
- debug:
msg: "import_playbook_B.yml: back from including tasks C"
rescue:
- debug:
msg: "import_playbook_B.yml: rescue fired"
- meta: end_play
include_playbook_C.yml
---
- debug:
msg: "include_playbook_C.yml: importing role"
- import_role:
name: ians_testing
- debug:
msg: "include_playbook_C.yml: back from importing role"
Role: ians_testing tasks/main.yml contains:
- debug:
msg: "This is the role"
tags: "{{ random_var }}_tag_name"
ians_testing vars/main.yml contains:
random_var: banana
Using our old AWX/ansible instance (AWX 15.0.1 and Ansible 2.9.14) we see:
/usr/lib/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography.exceptions import InvalidSignature
/var/lib/awx/venv/ansible/lib/python3.6/site-packages/paramiko/transport.py:219: CryptographyDeprecationWarning: Blowfish has been deprecated
"class": algorithms.Blowfish,
PLAY [localhost] ***************************************************************
TASK [debug] *******************************************************************
Monday 30 October 2023 14:07:26 +0000 (0:00:00.019) 0:00:00.019 ********
ok: [localhost] => {
"msg": "import_playbook_B.yml: including tasks C"
}
TASK [include_tasks] ***********************************************************
Monday 30 October 2023 14:07:26 +0000 (0:00:00.024) 0:00:00.044 ********
included: /tmp/awx_659235_i1yov0iu/project/include_playbook_C.yml for localhost
TASK [debug] *******************************************************************
Monday 30 October 2023 14:07:26 +0000 (0:00:00.334) 0:00:00.378 ********
ok: [localhost] => {
"msg": "include_playbook_C.yml: importing role"
}
TASK [ians_testing : debug] ****************************************************
Monday 30 October 2023 14:07:26 +0000 (0:00:00.027) 0:00:00.405 ********
ok: [localhost] => {
"msg": "This is the role"
}
TASK [debug] *******************************************************************
Monday 30 October 2023 14:07:26 +0000 (0:00:00.023) 0:00:00.429 ********
ok: [localhost] => {
"msg": "include_playbook_C.yml: back from importing role"
}
TASK [debug] *******************************************************************
Monday 30 October 2023 14:07:26 +0000 (0:00:00.022) 0:00:00.451 ********
ok: [localhost] => {
"msg": "import_playbook_B.yml: back from including tasks C"
}
PLAY RECAP *********************************************************************
localhost : ok=6 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Monday 30 October 2023 14:07:26 +0000 (0:00:00.021) 0:00:00.472 ********
===============================================================================
include_tasks ----------------------------------------------------------- 0.33s
debug ------------------------------------------------------------------- 0.03s
debug ------------------------------------------------------------------- 0.02s
ians_testing : debug ---------------------------------------------------- 0.02s
debug ------------------------------------------------------------------- 0.02s
debug ------------------------------------------------------------------- 0.02s
Using our new AWX/ansible instance (AWX 22.4.1.dev0+g6b381aa79e.d20230821 and Ansible 2.15.5) I see:
PLAY [localhost] ***************************************************************
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "import_playbook_B.yml: including tasks C"
}
TASK [include_tasks] ***********************************************************
included: /runner/project/include_playbook_C.yml for localhost
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "import_playbook_B.yml: rescue fired"
}
TASK [meta] ********************************************************************
NO MORE HOSTS LEFT *************************************************************
PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
If I import_role: straight from a playbook as opposed to from an imported playbook
---
- hosts: localhost
gather_facts: false
vars:
tasks:
- block:
- import_role:
name: ians_testing
- debug:
msg: "import_playbook_B.yml: including tasks C"
- include_tasks: include_playbook_C.yml
- debug:
msg: "import_playbook_B.yml: back from including tasks C"
rescue:
- debug:
msg: "import_playbook_B.yml: rescue fired"
- meta: end_play
then I get the more meaningful message:
PLAY [localhost] ***************************************************************
ERROR! 'random_var' is undefined. 'random_var' is undefined
Interestingly in this instance the rescue does not fire.
I hope that this is enough information but reach out to me if you need more. Thanks for your time,
Ian