| 1 |
--- |
| 2 |
- hosts: localhost |
| 3 |
# The gather_facts keyword has default values for its |
| 4 |
# options so module_defaults doesn't have much affect. |
| 5 |
gather_facts: no |
| 6 |
tags: |
| 7 |
- default_fact_module |
| 8 |
tasks: |
| 9 |
- name: set defaults for the action plugin |
| 10 |
gather_facts: |
| 11 |
module_defaults: |
| 12 |
gather_facts: |
| 13 |
gather_subset: min |
| 14 |
|
| 15 |
- assert: |
| 16 |
that: "gather_subset == ['min']" |
| 17 |
|
| 18 |
- name: set defaults for the module |
| 19 |
gather_facts: |
| 20 |
module_defaults: |
| 21 |
setup: |
| 22 |
gather_subset: '!all' |
| 23 |
|
| 24 |
- assert: |
| 25 |
that: "gather_subset == ['!all']" |
| 26 |
|
| 27 |
# Defaults for the action plugin win because they are |
| 28 |
# loaded first and options need to be omitted for |
| 29 |
# defaults to be used. |
| 30 |
- name: set defaults for the action plugin and module |
| 31 |
gather_facts: |
| 32 |
module_defaults: |
| 33 |
setup: |
| 34 |
gather_subset: '!all' |
| 35 |
gather_facts: |
| 36 |
gather_subset: min |
| 37 |
|
| 38 |
- assert: |
| 39 |
that: "gather_subset == ['min']" |
| 40 |
|
| 41 |
# The gather_facts 'smart' facts module is 'ansible.legacy.setup' by default. |
| 42 |
# If 'setup' (the unqualified name) is explicitly requested, FQCN module_defaults |
| 43 |
# would not apply. |
| 44 |
- name: set defaults for the fqcn module |
| 45 |
gather_facts: |
| 46 |
module_defaults: |
| 47 |
ansible.legacy.setup: |
| 48 |
gather_subset: '!all' |
| 49 |
|
| 50 |
- assert: |
| 51 |
that: "gather_subset == ['!all']" |
| 52 |
|
| 53 |
- hosts: localhost |
| 54 |
gather_facts: no |
| 55 |
tags: |
| 56 |
- custom_fact_module |
| 57 |
tasks: |
| 58 |
- name: set defaults for the module |
| 59 |
gather_facts: |
| 60 |
module_defaults: |
| 61 |
ansible.legacy.setup: |
| 62 |
gather_subset: '!all' |
| 63 |
|
| 64 |
- assert: |
| 65 |
that: |
| 66 |
- "gather_subset == ['!all']" |
| 67 |
|
| 68 |
# Defaults for the action plugin win. |
| 69 |
- name: set defaults for the action plugin and module |
| 70 |
gather_facts: |
| 71 |
module_defaults: |
| 72 |
gather_facts: |
| 73 |
gather_subset: min |
| 74 |
ansible.legacy.setup: |
| 75 |
gather_subset: '!all' |
| 76 |
|
| 77 |
- assert: |
| 78 |
that: |
| 79 |
- "gather_subset == ['min']" |
| 80 |
|
| 81 |
- hosts: localhost |
| 82 |
gather_facts: no |
| 83 |
tags: |
| 84 |
- networking |
| 85 |
tasks: |
| 86 |
- name: test that task args aren't used for fqcn network facts |
| 87 |
gather_facts: |
| 88 |
gather_subset: min |
| 89 |
vars: |
| 90 |
ansible_network_os: 'cisco.ios.ios' |
| 91 |
register: result |
| 92 |
|
| 93 |
- assert: |
| 94 |
that: |
| 95 |
- "ansible_facts.gather_subset == '!config'" |
| 96 |
|
| 97 |
- name: test that module_defaults are used for fqcn network facts |
| 98 |
gather_facts: |
| 99 |
vars: |
| 100 |
ansible_network_os: 'cisco.ios.ios' |
| 101 |
module_defaults: |
| 102 |
'cisco.ios.ios_facts': {'gather_subset': 'min'} |
| 103 |
register: result |
| 104 |
|
| 105 |
- assert: |
| 106 |
that: |
| 107 |
- "ansible_facts.gather_subset == 'min'" |
| 108 |
|
| 109 |
- name: test that task args aren't used for legacy network facts |
| 110 |
gather_facts: |
| 111 |
gather_subset: min |
| 112 |
vars: |
| 113 |
ansible_network_os: 'ios' |
| 114 |
register: result |
| 115 |
|
| 116 |
- assert: |
| 117 |
that: |
| 118 |
- "ansible_facts.gather_subset == '!config'" |
| 119 |
|
| 120 |
- name: test that module_defaults are used for legacy network facts |
| 121 |
gather_facts: |
| 122 |
vars: |
| 123 |
ansible_network_os: 'ios' |
| 124 |
module_defaults: |
| 125 |
'ios_facts': {'gather_subset': 'min'} |
| 126 |
register: result |
| 127 |
|
| 128 |
- assert: |
| 129 |
that: |
| 130 |
- "ansible_facts.gather_subset == 'min'" |
| 131 |
|
| 132 |
- name: Test module_defaults templating when the action and module differ |
| 133 |
hosts: localhost |
| 134 |
gather_facts: True |
| 135 |
tags: |
| 136 |
- templating |
| 137 |
vars: |
| 138 |
subset_facts: |
| 139 |
- "!all" |
| 140 |
- "!min" |
| 141 |
- env |
| 142 |
module_defaults: |
| 143 |
setup: |
| 144 |
gather_subset: "{{ subset_facts }}" |
| 145 |
tasks: |
| 146 |
- assert: |
| 147 |
that: |
| 148 |
- ansible_facts.gather_subset == subset_facts |