From 2603604fd64f3a811c1d423548cfc3239947754a Mon Sep 17 00:00:00 2001 From: Pilou Date: Thu, 23 Aug 2018 17:36:06 +0200 Subject: [PATCH] gather facts improvements (#44008) * gather_subset is a list of strings When gather_subset is an integer, a message pointing out the problem, current tb error is replaced by this one: ERROR! the field 'gather_subset' should be a list of (,), but the item '42' is a ... * gathering_facts test: ensure smart gathering is on --- lib/ansible/config/base.yml | 2 +- lib/ansible/playbook/play.py | 2 +- .../targets/gathering_facts/test_run_once.yml | 20 +++++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 4733c3bc76..9a0681d482 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -589,7 +589,7 @@ DEFAULT_GATHERING: choices: ['smart', 'explicit', 'implicit'] DEFAULT_GATHER_SUBSET: name: Gather facts subset - default: 'all' + default: ['all'] description: - Set the `gather_subset` option for the M(setup) task in the implicit fact gathering. See the module documentation for specifics. diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 3457a2281f..4437207405 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -59,7 +59,7 @@ class Play(Base, Taggable, Become): # Facts _fact_path = FieldAttribute(isa='string', default=None) _gather_facts = FieldAttribute(isa='bool', default=None, always_post_validate=True) - _gather_subset = FieldAttribute(isa='list', default=None, always_post_validate=True) + _gather_subset = FieldAttribute(isa='list', default=None, listof=string_types, always_post_validate=True) _gather_timeout = FieldAttribute(isa='int', default=None, always_post_validate=True) # Variable Attributes diff --git a/test/integration/targets/gathering_facts/test_run_once.yml b/test/integration/targets/gathering_facts/test_run_once.yml index 88ea155ddd..37023b242b 100644 --- a/test/integration/targets/gathering_facts/test_run_once.yml +++ b/test/integration/targets/gathering_facts/test_run_once.yml @@ -2,6 +2,10 @@ - hosts: facthost1 gather_facts: no tasks: + - name: check that smart gathering is enabled + fail: + msg: 'smart gathering must be enabled' + when: 'lookup("env", "ANSIBLE_GATHERING") != "smart"' - name: install test local facts copy: src: uuid.fact @@ -13,14 +17,14 @@ 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 }}" + - 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: