Skip to content

Commit

Permalink
Allow omit to work with include_role from_args (ansible#74879)
Browse files Browse the repository at this point in the history
* Allow omit to work with include_role from_args. Fixes ansible#66349

* Add clog frag
  • Loading branch information
sivel authored Jun 3, 2021
1 parent 605b1a1 commit 840825b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/66349-include-role-omit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
minor_changes:
- >-
``include_role`` - Allow use of ``omit`` in the ``from_*`` arguments
(https://github.com/ansible/ansible/issues/66349)
5 changes: 5 additions & 0 deletions lib/ansible/playbook/included_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

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
Expand Down Expand Up @@ -191,6 +192,10 @@ def process_include_results(results, iterator, loader, variable_manager):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- set_fact:
include_role_omit: true
2 changes: 2 additions & 0 deletions test/integration/targets/include_import/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"

0 comments on commit 840825b

Please sign in to comment.