summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2020-05-20 18:53:37 -0400
committerGitHub <noreply@github.com>2020-05-20 18:53:37 -0400
commit9281148b623d4e2e8302778d91af3e84ab9579a9 (patch)
treeaffef6f4891c854c480199985e64cbc246df889f /test
parentfe941a4045861bfe87340381e7992bcecdbc0291 (diff)
downloadansible-9281148b623d4e2e8302778d91af3e84ab9579a9.tar.gz
correctly merge multiple facts results (#68987)
* correctly merge multiple facts results fixes #68532
Diffstat (limited to 'test')
-rw-r--r--test/integration/targets/gathering_facts/aliases1
-rw-r--r--test/integration/targets/gathering_facts/library/facts_one25
-rw-r--r--test/integration/targets/gathering_facts/library/facts_two24
-rw-r--r--test/integration/targets/gathering_facts/one_two.json27
-rwxr-xr-xtest/integration/targets/gathering_facts/runme.sh7
-rw-r--r--test/integration/targets/gathering_facts/two_one.json27
-rw-r--r--test/integration/targets/gathering_facts/verify_merge_facts.yml41
-rw-r--r--test/sanity/ignore.txt2
8 files changed, 152 insertions, 2 deletions
diff --git a/test/integration/targets/gathering_facts/aliases b/test/integration/targets/gathering_facts/aliases
index b59832142f..0ee704e116 100644
--- a/test/integration/targets/gathering_facts/aliases
+++ b/test/integration/targets/gathering_facts/aliases
@@ -1 +1,2 @@
shippable/posix/group3
+needs/root
diff --git a/test/integration/targets/gathering_facts/library/facts_one b/test/integration/targets/gathering_facts/library/facts_one
new file mode 100644
index 0000000000..c74ab9a7df
--- /dev/null
+++ b/test/integration/targets/gathering_facts/library/facts_one
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+echo '{
+ "changed": false,
+ "ansible_facts": {
+ "factsone": "from facts_one module",
+ "common_fact": "also from facts_one module",
+ "common_dict_fact": {
+ "key_one": "from facts_one",
+ "key_two": "from facts_one"
+ },
+ "common_list_fact": [
+ "one",
+ "three",
+ "five"
+ ],
+ "common_list_fact2": [
+ "one",
+ "two",
+ "three",
+ "five",
+ "five"
+ ]
+ }
+}'
diff --git a/test/integration/targets/gathering_facts/library/facts_two b/test/integration/targets/gathering_facts/library/facts_two
new file mode 100644
index 0000000000..4e7c668450
--- /dev/null
+++ b/test/integration/targets/gathering_facts/library/facts_two
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+echo '{
+ "changed": false,
+ "ansible_facts": {
+ "factstwo": "from facts_two module",
+ "common_fact": "also from facts_two module",
+ "common_dict_fact": {
+ "key_two": "from facts_two",
+ "key_four": "from facts_two"
+ },
+ "common_list_fact": [
+ "one",
+ "two",
+ "four"
+ ],
+ "common_list_fact2": [
+ "one",
+ "two",
+ "four",
+ "four"
+ ]
+ }
+}'
diff --git a/test/integration/targets/gathering_facts/one_two.json b/test/integration/targets/gathering_facts/one_two.json
new file mode 100644
index 0000000000..ecc698c3b5
--- /dev/null
+++ b/test/integration/targets/gathering_facts/one_two.json
@@ -0,0 +1,27 @@
+{
+ "_ansible_facts_gathered": true,
+ "common_dict_fact": {
+ "key_four": "from facts_two",
+ "key_one": "from facts_one",
+ "key_two": "from facts_two"
+ },
+ "common_fact": "also from facts_two module",
+ "common_list_fact": [
+ "three",
+ "five",
+ "one",
+ "two",
+ "four"
+ ],
+ "common_list_fact2": [
+ "three",
+ "five",
+ "five",
+ "one",
+ "two",
+ "four",
+ "four"
+ ],
+ "factsone": "from facts_one module",
+ "factstwo": "from facts_two module"
+} \ No newline at end of file
diff --git a/test/integration/targets/gathering_facts/runme.sh b/test/integration/targets/gathering_facts/runme.sh
index ccea766281..770cd674c3 100755
--- a/test/integration/targets/gathering_facts/runme.sh
+++ b/test/integration/targets/gathering_facts/runme.sh
@@ -2,11 +2,14 @@
set -eux
-# ANSIBLE_CACHE_PLUGINS=cache_plugins/ ANSIBLE_CACHE_PLUGIN=none ansible-playbook test_gathering_facts.yml -i inventory -v "$@"
+#ANSIBLE_CACHE_PLUGINS=cache_plugins/ ANSIBLE_CACHE_PLUGIN=none ansible-playbook test_gathering_facts.yml -i inventory -v "$@"
ansible-playbook test_gathering_facts.yml -i inventory -v "$@"
-# ANSIBLE_CACHE_PLUGIN=base ansible-playbook test_gathering_facts.yml -i inventory -v "$@"
+#ANSIBLE_CACHE_PLUGIN=base ansible-playbook test_gathering_facts.yml -i inventory -v "$@"
ANSIBLE_GATHERING=smart ansible-playbook test_run_once.yml -i inventory -v "$@"
# ensure clean_facts is working properly
ansible-playbook test_prevent_injection.yml -i inventory -v "$@"
+
+# ensure fact merging is working properly
+ansible-playbook verify_merge_facts.yml -v "$@" -e 'ansible_facts_parallel: False'
diff --git a/test/integration/targets/gathering_facts/two_one.json b/test/integration/targets/gathering_facts/two_one.json
new file mode 100644
index 0000000000..4b34a2d575
--- /dev/null
+++ b/test/integration/targets/gathering_facts/two_one.json
@@ -0,0 +1,27 @@
+{
+ "_ansible_facts_gathered": true,
+ "common_dict_fact": {
+ "key_four": "from facts_two",
+ "key_one": "from facts_one",
+ "key_two": "from facts_one"
+ },
+ "common_fact": "also from facts_one module",
+ "common_list_fact": [
+ "two",
+ "four",
+ "one",
+ "three",
+ "five"
+ ],
+ "common_list_fact2": [
+ "four",
+ "four",
+ "one",
+ "two",
+ "three",
+ "five",
+ "five"
+ ],
+ "factsone": "from facts_one module",
+ "factstwo": "from facts_two module"
+} \ No newline at end of file
diff --git a/test/integration/targets/gathering_facts/verify_merge_facts.yml b/test/integration/targets/gathering_facts/verify_merge_facts.yml
new file mode 100644
index 0000000000..d214402438
--- /dev/null
+++ b/test/integration/targets/gathering_facts/verify_merge_facts.yml
@@ -0,0 +1,41 @@
+- name: rune one and two, verify merge is as expected
+ hosts: localhost
+ vars:
+ ansible_facts_modules:
+ - facts_one
+ - facts_two
+ tasks:
+
+ - name: populate original
+ include_vars:
+ name: original
+ file: one_two.json
+
+ - name: fail if ref file is updated
+ assert:
+ msg: '{{ansible_facts}} vs {{original}}'
+ that:
+ - ansible_facts|to_json(indent=4, sort_keys=True) == original|to_json(indent=4, sort_keys=True)
+
+ - name: clear existing facts for next play
+ meta: clear_facts
+
+
+- name: rune two and one, verify merge is as expected
+ hosts: localhost
+ vars:
+ ansible_facts_modules:
+ - facts_two
+ - facts_one
+ tasks:
+
+ - name: populate original
+ include_vars:
+ name: original
+ file: two_one.json
+
+ - name: fail if ref file is updated
+ assert:
+ msg: '{{ansible_facts}} vs {{original}}'
+ that:
+ - ansible_facts|to_json(indent=4, sort_keys=True) == original|to_json(indent=4, sort_keys=True)
diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt
index dd3f289e4d..8e7cbb9b41 100644
--- a/test/sanity/ignore.txt
+++ b/test/sanity/ignore.txt
@@ -282,6 +282,8 @@ test/integration/targets/collections_relative_imports/collection_root/ansible_co
test/integration/targets/expect/files/test_command.py future-import-boilerplate
test/integration/targets/expect/files/test_command.py metaclass-boilerplate
test/integration/targets/gathering_facts/library/bogus_facts shebang
+test/integration/targets/gathering_facts/library/facts_one shebang
+test/integration/targets/gathering_facts/library/facts_two shebang
test/integration/targets/get_url/files/testserver.py future-import-boilerplate
test/integration/targets/get_url/files/testserver.py metaclass-boilerplate
test/integration/targets/group/files/gidget.py future-import-boilerplate