mirror of https://github.com/ansible/ansible.git
Add set_fact_persistent action and module. (#26153)
* Add 'cacheable' param to set_fact action and module. Used just like set_fact, except facts set with cacheable: true will be stored in the fact cache if fact caching is enabled. set_fact normally only sets facts in the non_persistent_fact_cache, so they are lost between invocations. * update set_facts docs * use 'ansible_facts_cacheable' in module/actions result * pop fact cacheable related items out of args/results We dont want to use 'ansible_facts_cacheable' result item or 'cacheable' arg as actual facts, so pop them out of the dicts.pull/27667/head
parent
3476b005b9
commit
6fbd0a8bb5
@ -0,0 +1 @@
|
||||
posix/ci/group3
|
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
MYTMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
|
||||
trap 'rm -rf "${MYTMPDIR}"' EXIT
|
||||
|
||||
ANSIBLE_CACHE_PLUGIN=jsonfile ANSIBLE_CACHE_PLUGIN_CONNECTION="${MYTMPDIR}" ansible-playbook -i ../../inventory "$@" set_fact_cached_1.yml
|
||||
|
||||
ANSIBLE_CACHE_PLUGIN=jsonfile ANSIBLE_CACHE_PLUGIN_CONNECTION="${MYTMPDIR}" ansible-playbook -i ../../inventory "$@" set_fact_cached_2.yml
|
||||
|
||||
ANSIBLE_CACHE_PLUGIN=jsonfile ANSIBLE_CACHE_PLUGIN_CONNECTION="${MYTMPDIR}" ansible-playbook -i ../../inventory --flush-cache "$@" set_fact_no_cache.yml
|
||||
|
@ -0,0 +1,46 @@
|
||||
---
|
||||
- name: the first play
|
||||
hosts: localhost
|
||||
tasks:
|
||||
- name: show foobar fact before
|
||||
debug:
|
||||
var: ansible_foobar
|
||||
|
||||
- name: set a persistent fact foobar
|
||||
set_fact:
|
||||
ansible_foobar: 'blippy'
|
||||
cacheable: true
|
||||
|
||||
- name: show foobar fact after
|
||||
debug:
|
||||
var: ansible_foobar
|
||||
|
||||
- name: assert ansible_foobar is correct value
|
||||
assert:
|
||||
that:
|
||||
- ansible_foobar == 'blippy'
|
||||
|
||||
- name: set a non persistent fact that will not be cached
|
||||
set_fact:
|
||||
ansible_foobar_not_cached: 'this_should_not_be_cached'
|
||||
|
||||
- name: show ansible_foobar_not_cached fact after being set
|
||||
debug:
|
||||
var: ansible_foobar_not_cached
|
||||
|
||||
- name: assert ansible_foobar_not_cached is correct value
|
||||
assert:
|
||||
that:
|
||||
- ansible_foobar_not_cached == 'this_should_not_be_cached'
|
||||
|
||||
- name: the second play
|
||||
hosts: localhost
|
||||
tasks:
|
||||
- name: show foobar fact after second play
|
||||
debug:
|
||||
var: ansible_foobar
|
||||
|
||||
- name: assert ansible_foobar is correct value
|
||||
assert:
|
||||
that:
|
||||
- ansible_foobar == 'blippy'
|
@ -0,0 +1,21 @@
|
||||
---
|
||||
- name: A second playbook run with fact caching enabled
|
||||
hosts: localhost
|
||||
tasks:
|
||||
- name: show ansible_foobar fact
|
||||
debug:
|
||||
var: ansible_foobar
|
||||
|
||||
- name: assert ansible_foobar is correct value when read from cache
|
||||
assert:
|
||||
that:
|
||||
- ansible_foobar == 'blippy'
|
||||
|
||||
- name: show ansible_foobar_not_cached fact
|
||||
debug:
|
||||
var: ansible_foobar_not_cached
|
||||
|
||||
- name: assert ansible_foobar_not_cached is not cached
|
||||
assert:
|
||||
that:
|
||||
- ansible_foobar_not_cached is undefined
|
@ -0,0 +1,21 @@
|
||||
---
|
||||
- name: Running with fact caching enabled but with cache flushed
|
||||
hosts: localhost
|
||||
tasks:
|
||||
- name: show ansible_foobar fact
|
||||
debug:
|
||||
var: ansible_foobar
|
||||
|
||||
- name: assert ansible_foobar is correct value
|
||||
assert:
|
||||
that:
|
||||
- ansible_foobar is undefined
|
||||
|
||||
- name: show ansible_foobar_not_cached fact
|
||||
debug:
|
||||
var: ansible_foobar_not_cached
|
||||
|
||||
- name: assert ansible_foobar_not_cached is not cached
|
||||
assert:
|
||||
that:
|
||||
- ansible_foobar_not_cached is undefined
|
Loading…
Reference in New Issue