summaryrefslogtreecommitdiff
path: root/test/integration/targets/unsafe_writes
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2021-01-27 14:16:10 -0500
committerGitHub <noreply@github.com>2021-01-27 14:16:10 -0500
commitc7d4acc12f672d1b3a86119940193b3324584ac0 (patch)
tree97d71745d5f949791c8dc59a306441de4d7f4bf8 /test/integration/targets/unsafe_writes
parent2b0cd2c13f2021f839600d601f75dea2c0343ed1 (diff)
downloadansible-c7d4acc12f672d1b3a86119940193b3324584ac0.tar.gz
allow env to override unspecified unsafe_writes (#73282)
* allow env var for fallback value for unspecified unsafe_writes
Diffstat (limited to 'test/integration/targets/unsafe_writes')
-rw-r--r--test/integration/targets/unsafe_writes/basic.yml17
-rwxr-xr-xtest/integration/targets/unsafe_writes/runme.sh7
2 files changed, 23 insertions, 1 deletions
diff --git a/test/integration/targets/unsafe_writes/basic.yml b/test/integration/targets/unsafe_writes/basic.yml
index b173c7f872..410726ad0e 100644
--- a/test/integration/targets/unsafe_writes/basic.yml
+++ b/test/integration/targets/unsafe_writes/basic.yml
@@ -38,7 +38,7 @@
- copy_without is failed
- name: test overwriting file with unsafe
- copy: content=NEW dest={{testufile}} unsafe_writes=True
+ copy: content=NEWNOREALLY dest={{testufile}} unsafe_writes=True
register: copy_with
- name: ensure we properly changed
@@ -46,6 +46,21 @@
that:
- copy_with is changed
+ - name: test fallback env var
+ when: lookup('env', 'ANSIBLE_UNSAFE_WRITES') not in ('', None)
+ vars:
+ env_enabled: "{{lookup('env', 'ANSIBLE_UNSAFE_WRITES')|bool}}"
+ block:
+ - name: test overwriting file with unsafe depending on fallback environment setting
+ copy: content=NEWBUTNOTDIFFERENT dest={{testufile}}
+ register: copy_with_env
+ ignore_errors: True
+
+ - name: ensure we properly follow env var
+ assert:
+ msg: "Failed with envvar: {{env_enabled}}, due AUW: to {{q('env', 'ANSIBLE_UNSAFE_WRITES')}}"
+ that:
+ - env_enabled and copy_with_env is changed or not env_enabled and copy_with_env is failed
always:
- name: remove immutable flag from dir to prevent issues with cleanup
file: path={{testudir}} state=directory attributes="-i"
diff --git a/test/integration/targets/unsafe_writes/runme.sh b/test/integration/targets/unsafe_writes/runme.sh
index 5c37f727ee..791a5676b4 100755
--- a/test/integration/targets/unsafe_writes/runme.sh
+++ b/test/integration/targets/unsafe_writes/runme.sh
@@ -2,4 +2,11 @@
set -eux
+# test w/o fallback env var
ansible-playbook basic.yml -i ../../inventory -e "output_dir=${OUTPUT_DIR}" "$@"
+
+# test enabled fallback env var
+ANSIBLE_UNSAFE_WRITES=1 ansible-playbook basic.yml -i ../../inventory -e "output_dir=${OUTPUT_DIR}" "$@"
+
+# test disnabled fallback env var
+ANSIBLE_UNSAFE_WRITES=0 ansible-playbook basic.yml -i ../../inventory -e "output_dir=${OUTPUT_DIR}" "$@"