Skip to content

Commit 875adef

Browse files
authored
Expose rules that have autofix capability in docs (#3770)
1 parent e6bc4c7 commit 875adef

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

docs/autofix.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Autofix
2+
3+
Ansible-lint autofix can fix or simplify fixing issues identified by that rule. `ansible-lint --fix` will reformat YAML files and run transform for the given
4+
rules. You can limit the effective rule transforms (the 'write_list') by passing
5+
a keywords 'all' or 'none' or a comma separated list of rule ids or rule tags.
6+
By default it will run all transforms (effectively `write_list: ["all"]`).
7+
You can disable running transforms by setting `write_list: ["none"]`. Or only enable a subset of rule transforms by listing rules/tags here.
8+
9+
Following is the list of supported rules covered under autofix functionality.
10+
11+
- [command-instead-of-shell](rules/command-instead-of-shell.md#auto-fixing-capability)
12+
- [deprecated-local-action](rules/deprecated-local-action.md)
13+
- [fqcn](rules/fqcn.md)
14+
- [jinja](rules/jinja.md)
15+
- [key-order](rules/key-order.md)
16+
- [name](rules/name.md)
17+
- [no-free-form](rules/no-free-form.md)
18+
- [no-jinja-when](rules/no-jinja-when.md)
19+
- [no-log-password](rules/no-log-password.md)
20+
- [partial-become](rules/partial-become.md)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ nav:
5353
- usage.md
5454
- configuring.md
5555
- profiles.md
56+
- autofix.md
5657
- Rules:
5758
- index: rules/index.md
5859
- rules/args.md

src/ansiblelint/rules/command_instead_of_shell.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,65 @@ environment variable expansion or chaining multiple commands using pipes.
2828
ansible.builtin.command: echo hello
2929
changed_when: false
3030
```
31+
32+
## Auto-fixing capability
33+
34+
### Before autofix
35+
36+
```yaml
37+
---
38+
- name: Fixture
39+
hosts: localhost
40+
tasks:
41+
- name: Shell no pipe
42+
ansible.builtin.shell:
43+
cmd: echo hello
44+
changed_when: false
45+
46+
- name: Shell with jinja filter
47+
ansible.builtin.shell:
48+
cmd: echo {{ "hello" | upper }}
49+
changed_when: false
50+
51+
- name: Shell with jinja filter (fqcn)
52+
ansible.builtin.shell:
53+
cmd: echo {{ "hello" | upper }}
54+
changed_when: false
55+
56+
- name: Command with executable parameter
57+
ansible.builtin.shell:
58+
cmd: clear
59+
args:
60+
executable: /bin/bash
61+
changed_when: false
62+
```
63+
64+
### After autofix
65+
66+
```yaml
67+
---
68+
- name: Fixture
69+
hosts: localhost
70+
tasks:
71+
- name: Shell no pipe
72+
ansible.builtin.command:
73+
cmd: echo hello
74+
changed_when: false
75+
76+
- name: Shell with jinja filter
77+
ansible.builtin.command:
78+
cmd: echo {{ "hello" | upper }}
79+
changed_when: false
80+
81+
- name: Shell with jinja filter (fqcn)
82+
ansible.builtin.command:
83+
cmd: echo {{ "hello" | upper }}
84+
changed_when: false
85+
86+
- name: Command with executable parameter
87+
ansible.builtin.shell:
88+
cmd: clear
89+
args:
90+
executable: /bin/bash
91+
changed_when: false
92+
```

0 commit comments

Comments
 (0)