summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/gathering_facts/test_module_defaults.yml
blob: 038b8ecf7925f9786e1fa50edfb165440f3ce849 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
- hosts: localhost
  # The gather_facts keyword has default values for its
  # options so module_defaults doesn't have much affect.
  gather_facts: no
  tags:
    - default_fact_module
  tasks:
    - name: set defaults for the action plugin
      gather_facts:
      module_defaults:
        gather_facts:
          gather_subset: min

    - assert:
        that: "gather_subset == ['min']"

    - name: set defaults for the module
      gather_facts:
      module_defaults:
        setup:
          gather_subset: '!all'

    - assert:
        that: "gather_subset == ['!all']"

    # Defaults for the action plugin win because they are
    # loaded first and options need to be omitted for
    # defaults to be used.
    - name: set defaults for the action plugin and module
      gather_facts:
      module_defaults:
        setup:
          gather_subset: '!all'
        gather_facts:
          gather_subset: min

    - assert:
        that: "gather_subset == ['min']"

    # The gather_facts 'smart' facts module is 'ansible.legacy.setup' by default.
    # If 'setup' (the unqualified name) is explicitly requested, FQCN module_defaults
    # would not apply.
    - name: set defaults for the fqcn module
      gather_facts:
      module_defaults:
        ansible.legacy.setup:
          gather_subset: '!all'

    - assert:
        that: "gather_subset == ['!all']"

- hosts: localhost
  gather_facts: no
  tags:
    - custom_fact_module
  tasks:
    - name: set defaults for the module
      gather_facts:
      module_defaults:
        ansible.legacy.setup:
          gather_subset: '!all'

    - assert:
        that:
          - "gather_subset == ['!all']"

    # Defaults for the action plugin win.
    - name: set defaults for the action plugin and module
      gather_facts:
      module_defaults:
        gather_facts:
          gather_subset: min
        ansible.legacy.setup:
          gather_subset: '!all'

    - assert:
        that:
          - "gather_subset == ['min']"

- hosts: localhost
  gather_facts: no
  tags:
    - networking
  tasks:
    - name: test that task args aren't used for fqcn network facts
      gather_facts:
        gather_subset: min
      vars:
        ansible_network_os: 'cisco.ios.ios'
      register: result

    - assert:
        that:
          - "ansible_facts.gather_subset == '!config'"

    - name: test that module_defaults are used for fqcn network facts
      gather_facts:
      vars:
        ansible_network_os: 'cisco.ios.ios'
      module_defaults:
        'cisco.ios.ios_facts': {'gather_subset': 'min'}
      register: result

    - assert:
        that:
          - "ansible_facts.gather_subset == 'min'"

    - name: test that task args aren't used for legacy network facts
      gather_facts:
        gather_subset: min
      vars:
        ansible_network_os: 'ios'
      register: result

    - assert:
        that:
          - "ansible_facts.gather_subset == '!config'"

    - name: test that module_defaults are used for legacy network facts
      gather_facts:
      vars:
        ansible_network_os: 'ios'
      module_defaults:
        'ios_facts': {'gather_subset': 'min'}
      register: result

    - assert:
        that:
          - "ansible_facts.gather_subset == 'min'"