diff --git a/changelogs/fragments/fix_import_notify.yml b/changelogs/fragments/fix_import_notify.yml new file mode 100644 index 00000000000..c94635f96df --- /dev/null +++ b/changelogs/fragments/fix_import_notify.yml @@ -0,0 +1,2 @@ +bugfixes: + - notify keyword is not ignored anymore on import_tasks, also able to apply to blocks now. diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 825e1096c54..d4cee0c84ed 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -61,6 +61,31 @@ class _DeprecatedSequenceConstant(Sequence): # CONSTANTS ### yes, actual ones + +# The following are hard-coded action names +_ACTION_DEBUG = add_internal_fqcns(('debug', )) +_ACTION_IMPORT_PLAYBOOK = add_internal_fqcns(('import_playbook', )) +_ACTION_IMPORT_ROLE = add_internal_fqcns(('import_role', )) +_ACTION_IMPORT_TASKS = add_internal_fqcns(('import_tasks', )) +_ACTION_INCLUDE = add_internal_fqcns(('include', )) +_ACTION_INCLUDE_ROLE = add_internal_fqcns(('include_role', )) +_ACTION_INCLUDE_TASKS = add_internal_fqcns(('include_tasks', )) +_ACTION_INCLUDE_VARS = add_internal_fqcns(('include_vars', )) +_ACTION_META = add_internal_fqcns(('meta', )) +_ACTION_SET_FACT = add_internal_fqcns(('set_fact', )) +_ACTION_SETUP = add_internal_fqcns(('setup', )) +_ACTION_HAS_CMD = add_internal_fqcns(('command', 'shell', 'script')) +_ACTION_ALLOWS_RAW_ARGS = _ACTION_HAS_CMD + add_internal_fqcns(('raw', )) +_ACTION_ALL_INCLUDES = _ACTION_INCLUDE + _ACTION_INCLUDE_TASKS + _ACTION_INCLUDE_ROLE +_ACTION_ALL_IMPORT_PLAYBOOKS = _ACTION_INCLUDE + _ACTION_IMPORT_PLAYBOOK +_ACTION_ALL_INCLUDE_IMPORT_TASKS = _ACTION_INCLUDE + _ACTION_INCLUDE_TASKS + _ACTION_IMPORT_TASKS +_ACTION_ALL_PROPER_INCLUDE_IMPORT_ROLES = _ACTION_INCLUDE_ROLE + _ACTION_IMPORT_ROLE +_ACTION_ALL_PROPER_INCLUDE_IMPORT_TASKS = _ACTION_INCLUDE_TASKS + _ACTION_IMPORT_TASKS +_ACTION_ALL_INCLUDE_ROLE_TASKS = _ACTION_INCLUDE_ROLE + _ACTION_INCLUDE_TASKS +_ACTION_ALL_INCLUDE_TASKS = _ACTION_INCLUDE + _ACTION_INCLUDE_TASKS +_ACTION_FACT_GATHERING = _ACTION_SETUP + add_internal_fqcns(('gather_facts', )) +_ACTION_WITH_CLEAN_FACTS = _ACTION_SET_FACT + _ACTION_INCLUDE_VARS + # http://nezzen.net/2008/06/23/colored-text-in-python-using-ansi-escape-sequences/ COLOR_CODES = { 'black': u'0;30', 'bright gray': u'0;37', @@ -178,28 +203,3 @@ for setting in config.data.get_settings(): for warn in config.WARNINGS: _warning(warn) - - -# The following are hard-coded action names -_ACTION_DEBUG = add_internal_fqcns(('debug', )) -_ACTION_IMPORT_PLAYBOOK = add_internal_fqcns(('import_playbook', )) -_ACTION_IMPORT_ROLE = add_internal_fqcns(('import_role', )) -_ACTION_IMPORT_TASKS = add_internal_fqcns(('import_tasks', )) -_ACTION_INCLUDE = add_internal_fqcns(('include', )) -_ACTION_INCLUDE_ROLE = add_internal_fqcns(('include_role', )) -_ACTION_INCLUDE_TASKS = add_internal_fqcns(('include_tasks', )) -_ACTION_INCLUDE_VARS = add_internal_fqcns(('include_vars', )) -_ACTION_META = add_internal_fqcns(('meta', )) -_ACTION_SET_FACT = add_internal_fqcns(('set_fact', )) -_ACTION_SETUP = add_internal_fqcns(('setup', )) -_ACTION_HAS_CMD = add_internal_fqcns(('command', 'shell', 'script')) -_ACTION_ALLOWS_RAW_ARGS = _ACTION_HAS_CMD + add_internal_fqcns(('raw', )) -_ACTION_ALL_INCLUDES = _ACTION_INCLUDE + _ACTION_INCLUDE_TASKS + _ACTION_INCLUDE_ROLE -_ACTION_ALL_IMPORT_PLAYBOOKS = _ACTION_INCLUDE + _ACTION_IMPORT_PLAYBOOK -_ACTION_ALL_INCLUDE_IMPORT_TASKS = _ACTION_INCLUDE + _ACTION_INCLUDE_TASKS + _ACTION_IMPORT_TASKS -_ACTION_ALL_PROPER_INCLUDE_IMPORT_ROLES = _ACTION_INCLUDE_ROLE + _ACTION_IMPORT_ROLE -_ACTION_ALL_PROPER_INCLUDE_IMPORT_TASKS = _ACTION_INCLUDE_TASKS + _ACTION_IMPORT_TASKS -_ACTION_ALL_INCLUDE_ROLE_TASKS = _ACTION_INCLUDE_ROLE + _ACTION_INCLUDE_TASKS -_ACTION_ALL_INCLUDE_TASKS = _ACTION_INCLUDE + _ACTION_INCLUDE_TASKS -_ACTION_FACT_GATHERING = _ACTION_SETUP + add_internal_fqcns(('gather_facts', )) -_ACTION_WITH_CLEAN_FACTS = _ACTION_SET_FACT + _ACTION_INCLUDE_VARS diff --git a/lib/ansible/playbook/block.py b/lib/ansible/playbook/block.py index 62d79d1b7be..3c8ecc76291 100644 --- a/lib/ansible/playbook/block.py +++ b/lib/ansible/playbook/block.py @@ -38,7 +38,8 @@ class Block(Base, Conditional, CollectionSearch, Taggable): _rescue = FieldAttribute(isa='list', default=list, inherit=False) _always = FieldAttribute(isa='list', default=list, inherit=False) - # other fields + # other fields for task compat + _notify = FieldAttribute(isa='list') _delegate_to = FieldAttribute(isa='string') _delegate_facts = FieldAttribute(isa='bool') diff --git a/test/integration/targets/blocks/inherit_notify.yml b/test/integration/targets/blocks/inherit_notify.yml new file mode 100644 index 00000000000..d8e87423df7 --- /dev/null +++ b/test/integration/targets/blocks/inherit_notify.yml @@ -0,0 +1,19 @@ +- hosts: localhost + gather_facts: false + tasks: + - name: test notify inheritance in block + notify: hello + block: + - debug: msg='trigger it' + changed_when: true + + handlers: + - name: hello + set_fact: hello=world + + post_tasks: + - name: ensure handler ran + assert: + that: + - hello is defined + - "hello == 'world'" diff --git a/test/integration/targets/blocks/runme.sh b/test/integration/targets/blocks/runme.sh index 535126835d2..63bcd3fc3c7 100755 --- a/test/integration/targets/blocks/runme.sh +++ b/test/integration/targets/blocks/runme.sh @@ -100,3 +100,6 @@ cat role_complete_test.out [ "$(grep -c 'Tagged task' role_complete_test.out)" -eq 2 ] [ "$(grep -c 'Not tagged task' role_complete_test.out)" -eq 0 ] rm -f role_complete_test.out + +# test notify inheritance +ansible-playbook inherit_notify.yml "$@" diff --git a/test/integration/targets/import_tasks/aliases b/test/integration/targets/import_tasks/aliases new file mode 100644 index 00000000000..fff62d9f20f --- /dev/null +++ b/test/integration/targets/import_tasks/aliases @@ -0,0 +1,2 @@ +shippable/posix/group5 +skip/aix diff --git a/test/integration/targets/import_tasks/inherit_notify.yml b/test/integration/targets/import_tasks/inherit_notify.yml new file mode 100644 index 00000000000..cf418f9df3d --- /dev/null +++ b/test/integration/targets/import_tasks/inherit_notify.yml @@ -0,0 +1,15 @@ +- hosts: localhost + gather_facts: false + pre_tasks: + - import_tasks: tasks/trigger_change.yml + notify: hello + + handlers: + - name: hello + set_fact: hello=world + + tasks: + - name: ensure handler ran + assert: + that: + - "hello is defined and hello == 'world'" diff --git a/test/integration/targets/import_tasks/runme.sh b/test/integration/targets/import_tasks/runme.sh new file mode 100755 index 00000000000..ea3529b5c91 --- /dev/null +++ b/test/integration/targets/import_tasks/runme.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook inherit_notify.yml "$@" diff --git a/test/integration/targets/import_tasks/tasks/trigger_change.yml b/test/integration/targets/import_tasks/tasks/trigger_change.yml new file mode 100644 index 00000000000..6ee45515219 --- /dev/null +++ b/test/integration/targets/import_tasks/tasks/trigger_change.yml @@ -0,0 +1,2 @@ +- debug: msg="I trigger changed!" + changed_when: true diff --git a/test/integration/targets/includes/inherit_notify.yml b/test/integration/targets/includes/inherit_notify.yml new file mode 100644 index 00000000000..f868be16eec --- /dev/null +++ b/test/integration/targets/includes/inherit_notify.yml @@ -0,0 +1,18 @@ +- hosts: localhost + gather_facts: false + pre_tasks: + - include_tasks: + file: tasks/trigger_change.yml + apply: + notify: hello + + handlers: + - name: hello + set_fact: hello=world + + tasks: + - name: ensure handler ran + assert: + that: + - hello is defined + - "hello == 'world'" diff --git a/test/integration/targets/includes/runme.sh b/test/integration/targets/includes/runme.sh index dff40029b1b..70ff105bd1d 100755 --- a/test/integration/targets/includes/runme.sh +++ b/test/integration/targets/includes/runme.sh @@ -3,3 +3,5 @@ set -eux ansible-playbook test_includes.yml -i ../../inventory "$@" + +ansible-playbook inherit_notify.yml "$@" diff --git a/test/integration/targets/includes/tasks/trigger_change.yml b/test/integration/targets/includes/tasks/trigger_change.yml new file mode 100644 index 00000000000..6ee45515219 --- /dev/null +++ b/test/integration/targets/includes/tasks/trigger_change.yml @@ -0,0 +1,2 @@ +- debug: msg="I trigger changed!" + changed_when: true