From 64e15932430fc8b9d18c32c463bcfae6f8b2be75 Mon Sep 17 00:00:00 2001 From: Pilou Date: Mon, 15 Jan 2018 17:02:24 +0100 Subject: [PATCH] set_fact: handle 'cacheable=value' form (#34871) * Ensure fact isn't cached when cacheable=val form is used * Don't cache fact when cacheable=val form is used --- lib/ansible/plugins/action/set_fact.py | 2 +- .../targets/set_fact/set_fact_cached_1.yml | 12 ++++++++++++ .../targets/set_fact/set_fact_cached_2.yml | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/action/set_fact.py b/lib/ansible/plugins/action/set_fact.py index 536bb69c6dd..623c6be8b09 100644 --- a/lib/ansible/plugins/action/set_fact.py +++ b/lib/ansible/plugins/action/set_fact.py @@ -36,7 +36,7 @@ class ActionModule(ActionBase): facts = dict() - cacheable = bool(self._task.args.pop('cacheable', False)) + cacheable = boolean(self._task.args.pop('cacheable', False)) if self._task.args: for (k, v) in iteritems(self._task.args): diff --git a/test/integration/targets/set_fact/set_fact_cached_1.yml b/test/integration/targets/set_fact/set_fact_cached_1.yml index 65c6c4dfa5c..450f8da28ea 100644 --- a/test/integration/targets/set_fact/set_fact_cached_1.yml +++ b/test/integration/targets/set_fact/set_fact_cached_1.yml @@ -33,6 +33,18 @@ that: - ansible_foobar_not_cached == 'this_should_not_be_cached' + - name: set another non persistent fact that will not be cached + set_fact: "cacheable=no fact_not_cached='this_should_not_be_cached!'" + + - name: show fact_not_cached fact after being set + debug: + var: fact_not_cached + + - name: assert fact_not_cached is correct value + assert: + that: + - fact_not_cached == 'this_should_not_be_cached!' + - name: the second play hosts: localhost tasks: diff --git a/test/integration/targets/set_fact/set_fact_cached_2.yml b/test/integration/targets/set_fact/set_fact_cached_2.yml index abfc67f38b5..7ca26b9dcb0 100644 --- a/test/integration/targets/set_fact/set_fact_cached_2.yml +++ b/test/integration/targets/set_fact/set_fact_cached_2.yml @@ -19,3 +19,12 @@ assert: that: - ansible_foobar_not_cached is undefined + + - name: show fact_not_cached fact + debug: + var: fact_not_cached + + - name: assert fact_not_cached is not cached + assert: + that: + - fact_not_cached is undefined