blob: 567d0fdb989791f98391b6d78607f46cbae0e280 (
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
|
# args
This rule validates if the task arguments conform with the plugin documentation.
The rule validation will check if the option name is valid and has the correct
value along with conditionals on the options like `mutually_exclusive`,
`required_together`, `required_one_of` and so on.
For more information see the
[argument spec validator](https://docs.ansible.com/ansible/latest/reference_appendices/module_utils.html#argumentspecvalidator)
topic in the Ansible module utility documentation.
Possible messages:
- `args[module]` - missing required arguments: ...
- `args[module]` - missing parameter(s) required by ...
## Problematic Code
```yaml
---
- name: Fixture to validate module options failure scenarios
hosts: localhost
tasks:
- name: Clone content repository
ansible.builtin.git: # <- Required option `repo` is missing.
dest: /home/www
accept_hostkey: true
version: master
update: false
- name: Enable service httpd and ensure it is not masked
ansible.builtin.systemd: # <- Missing 'name' parameter required by 'enabled'.
enabled: true
masked: false
- name: Use quiet to avoid verbose output
ansible.builtin.assert:
test:
- my_param <= 100
- my_param >= 0
quiet: invalid # <- Value for option `quiet` is invalid.
```
## Correct Code
```yaml
---
- name: Fixture to validate module options pass scenario
hosts: localhost
tasks:
- name: Clone content repository
ansible.builtin.git: # <- Contains required option `repo`.
repo: https://github.com/ansible/ansible-examples
dest: /home/www
accept_hostkey: true
version: master
update: false
- name: Enable service httpd and ensure it is not masked
ansible.builtin.systemd: # <- Contains 'name' parameter required by 'enabled'.
name: httpd
enabled: false
masked: false
- name: Use quiet to avoid verbose output
ansible.builtin.assert:
that:
- my_param <= 100
- my_param >= 0
quiet: True # <- Has correct type value for option `quiet` which is boolean.
```
## Special cases
In some complex cases where you are using jinja expressions, the linter may not
able to fully validate all the possible values and report a false positive. The
example below would usually report
`parameters are mutually exclusive: data|file|keyserver|url` but because we
added `# noqa: args[module]` it will just pass.
```yaml
- name: Add apt keys # noqa: args[module]
become: true
ansible.builtin.apt_key:
url: "{{ zj_item['url'] | default(omit) }}"
data: "{{ zj_item['data'] | default(omit) }}"
loop: "{{ repositories_keys }}"
loop_control:
loop_var: zj_item
```
|