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:
Matt Martz 2021-06-03 14:07:16 -05:00 committed by GitHub
parent 605b1a1c5c
commit 840825b79c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 0 deletions

View file

@ -0,0 +1,4 @@
minor_changes:
- >-
``include_role`` - Allow use of ``omit`` in the ``from_*`` arguments
(https://github.com/ansible/ansible/issues/66349)

View file

@ -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

View file

@ -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)

View file

@ -0,0 +1,2 @@
- set_fact:
include_role_omit: true

View file

@ -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 "$@"