Allow omit to work with include_role from_args (#74879)
* Allow omit to work with include_role from_args. Fixes #66349 * Add clog frag
This commit is contained in:
parent
605b1a1c5c
commit
840825b79c
5 changed files with 25 additions and 0 deletions
4
changelogs/fragments/66349-include-role-omit.yml
Normal file
4
changelogs/fragments/66349-include-role-omit.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
minor_changes:
|
||||
- >-
|
||||
``include_role`` - Allow use of ``omit`` in the ``from_*`` arguments
|
||||
(https://github.com/ansible/ansible/issues/66349)
|
|
@ -23,6 +23,7 @@ import os
|
|||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.executor.task_executor import remove_omit
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.playbook.handler import Handler
|
||||
from ansible.playbook.task_include import TaskInclude
|
||||
|
@ -191,6 +192,10 @@ class IncludedFile:
|
|||
from_key = from_arg.replace('_from', '')
|
||||
new_task._from_files[from_key] = templar.template(include_args.pop(from_arg))
|
||||
|
||||
omit_token = task_vars.get('omit')
|
||||
if omit_token:
|
||||
new_task._from_files = remove_omit(new_task._from_files, omit_token)
|
||||
|
||||
inc_file = IncludedFile(role_name, include_args, special_vars, new_task, is_role=True)
|
||||
|
||||
idx = 0
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
- hosts: localhost
|
||||
gather_facts: false
|
||||
vars:
|
||||
include_role_omit: false
|
||||
tasks:
|
||||
- include_role:
|
||||
name: foo
|
||||
tasks_from: '{{ omit }}'
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- include_role_omit is sameas(true)
|
|
@ -0,0 +1,2 @@
|
|||
- set_fact:
|
||||
include_role_omit: true
|
|
@ -126,3 +126,5 @@ ANSIBLE_HOST_PATTERN_MISMATCH=error ansible-playbook empty_group_warning/playboo
|
|||
|
||||
ansible-playbook test_include_loop.yml "$@"
|
||||
ansible-playbook test_include_loop_fqcn.yml "$@"
|
||||
|
||||
ansible-playbook include_role_omit/playbook.yml "$@"
|
||||
|
|
Loading…
Reference in a new issue