summaryrefslogtreecommitdiff
path: root/test/integration/targets/gathering_facts
diff options
context:
space:
mode:
authorMickaël Guérin <kael@crocobox.org>2018-05-04 21:33:32 +0200
committerBrian Coca <bcoca@users.noreply.github.com>2018-05-04 15:33:32 -0400
commit8ac69b0a5fdba07101e221f52cbcd88dd41a4791 (patch)
tree89b879f209fc6e906926c6537fddcdf7303e8393 /test/integration/targets/gathering_facts
parent05d5d21d1cec7cb6c4427eabf49726bddce6bd4f (diff)
downloadansible-8ac69b0a5fdba07101e221f52cbcd88dd41a4791.tar.gz
Fix gathering facts in run_once play (#39453)
* Fix gathering facts in run_once play Fixes https://github.com/ansible/ansible/issues/39312 * Check that run_once doesn't prevent fact gathering
Diffstat (limited to 'test/integration/targets/gathering_facts')
-rwxr-xr-xtest/integration/targets/gathering_facts/runme.sh2
-rw-r--r--test/integration/targets/gathering_facts/test_run_once.yml28
-rw-r--r--test/integration/targets/gathering_facts/uuid.fact10
3 files changed, 40 insertions, 0 deletions
diff --git a/test/integration/targets/gathering_facts/runme.sh b/test/integration/targets/gathering_facts/runme.sh
index e4c7b3844a..4baf8379e3 100755
--- a/test/integration/targets/gathering_facts/runme.sh
+++ b/test/integration/targets/gathering_facts/runme.sh
@@ -5,3 +5,5 @@ set -eux
# 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_GATHERING=smart ansible-playbook test_run_once.yml -i ../../inventory -v "$@"
diff --git a/test/integration/targets/gathering_facts/test_run_once.yml b/test/integration/targets/gathering_facts/test_run_once.yml
new file mode 100644
index 0000000000..88ea155ddd
--- /dev/null
+++ b/test/integration/targets/gathering_facts/test_run_once.yml
@@ -0,0 +1,28 @@
+---
+- hosts: facthost1
+ gather_facts: no
+ tasks:
+ - name: install test local facts
+ copy:
+ src: uuid.fact
+ dest: /etc/ansible/facts.d/
+ mode: 0755
+
+- hosts: facthost1,facthost2
+ gather_facts: yes
+ run_once: yes
+ tasks:
+ - block:
+ - name: 'Check the same host is used'
+ assert:
+ that: 'hostvars.facthost1.ansible_fqdn == hostvars.facthost2.ansible_fqdn'
+ msg: 'This test requires 2 inventory hosts referring to the same host.'
+ - name: "Check that run_once doesn't prevent fact gathering (#39453)"
+ assert:
+ that: 'hostvars.facthost1.ansible_local.uuid != hostvars.facthost2.ansible_local.uuid'
+ msg: "{{ 'Same value for ansible_local.uuid on both hosts: ' ~ hostvars.facthost1.ansible_local.uuid }}"
+ always:
+ - name: remove test local facts
+ file:
+ path: /etc/ansible/facts.d/uuid.fact
+ state: absent
diff --git a/test/integration/targets/gathering_facts/uuid.fact b/test/integration/targets/gathering_facts/uuid.fact
new file mode 100644
index 0000000000..79e3f62677
--- /dev/null
+++ b/test/integration/targets/gathering_facts/uuid.fact
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+import json
+import uuid
+
+
+# return a random string
+print(json.dumps(str(uuid.uuid4())))