Configurable and parallel gather facts (#49399)

* Configurable list of facts modules (#31783)

 - allow for args dict for specific modules
 - add way to pass parameters
 - avoid facts poluting test
 - move to 'facts gathered' flag
 - add 'gathering' setting tests
 - allow parallel option in case serialization is too slow
 - added support to automatically map network facts
   uses "smart" connection mapping
This commit is contained in:
Brian Coca 2019-03-08 13:08:37 -05:00 committed by GitHub
commit 8940732b58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 268 additions and 3 deletions

View file

@ -0,0 +1 @@
shippable/posix/group3

View file

@ -0,0 +1,14 @@
- hosts: testhost
tasks:
- name: ensure facts have not been collected
assert:
that:
- ansible_facts is undefined or not 'fqdn' in ansible_facts
- hosts: testhost
gather_facts: True
tasks:
- name: ensure facts have been collected
assert:
that:
- ansible_facts is defined and 'fqdn' in ansible_facts

View file

@ -0,0 +1,23 @@
- hosts: testhost
tasks:
- name: check that facts were gathered but no local facts exist
assert:
that:
- ansible_facts is defined and 'fqdn' in ansible_facts
- not 'uuid' in ansible_local
- name: create 'local facts' for next gathering
copy:
src: uuid.fact
dest: /etc/ansible/facts.d/
mode: 0755
- hosts: testhost
tasks:
- name: ensure facts are gathered and includes the new 'local facts' created above
assert:
that:
- ansible_facts is defined and 'fqdn' in ansible_facts
- "'uuid' in ansible_local"
- name: cleanup 'local facts' from target
file: path=/etc/ansible/facts.d/uuid.fact state=absent

View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -eux
ANSIBLE_GATHERING=smart ansible-playbook smart.yml --flush-cache -i ../../inventory -v "$@"
ANSIBLE_GATHERING=implicit ansible-playbook implicit.yml --flush-cache -i ../../inventory -v "$@"
ANSIBLE_GATHERING=explicit ansible-playbook explicit.yml --flush-cache -i ../../inventory -v "$@"

View file

@ -0,0 +1,23 @@
- hosts: testhost
tasks:
- name: ensure facts are gathered but no local exists
assert:
that:
- ansible_facts is defined and 'fqdn' in ansible_facts
- not 'uuid' in ansible_local
- name: create local facts for latter test
copy:
src: uuid.fact
dest: /etc/ansible/facts.d/
mode: 0755
- hosts: testhost
tasks:
- name: ensure we still have facts, but didnt pickup new local ones
assert:
that:
- ansible_facts is defined and 'fqdn' in ansible_facts
- not 'uuid' in ansible_local
- name: remove local facts file
file: path=/etc/ansible/facts.d/uuid.fact state=absent

View file

@ -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())))

View file

@ -1,5 +1,6 @@
- name: test playbook for ansible-pull
hosts: all
gather_facts: False
tasks:
- name: debug output
debug: msg="test task"