forked from ansible/ansible-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto-fixing implementation for
partial-become
rule (ansible#3692)
Co-authored-by: Bradley A. Thornton <[email protected]>
- Loading branch information
1 parent
453269b
commit 8cd9281
Showing
11 changed files
with
437 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 10 additions & 11 deletions
21
examples/playbooks/rule-partial-become-without-become-fail.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
--- | ||
- hosts: localhost | ||
name: Use of become_user without become play | ||
- name: Use of become_user without become at play level | ||
hosts: localhost | ||
become_user: root | ||
|
||
tasks: | ||
- ansible.builtin.debug: | ||
- name: A task without issues | ||
ansible.builtin.debug: | ||
msg: hello | ||
|
||
- hosts: localhost | ||
|
||
- name: Use of become_user without become at task level | ||
hosts: localhost | ||
tasks: | ||
- name: Use of become_user without become task | ||
ansible.builtin.command: whoami | ||
become_user: postgres | ||
changed_when: false | ||
|
||
- hosts: localhost | ||
|
||
- name: Use of become_user without become at task level | ||
hosts: localhost | ||
tasks: | ||
- name: A block with become and become_user on different tasks | ||
block: | ||
- name: Sample become | ||
become: true | ||
ansible.builtin.command: whoami | ||
- name: Sample become_user | ||
become_user: postgres | ||
ansible.builtin.command: whoami | ||
become_user: true | ||
changed_when: false |
20 changes: 12 additions & 8 deletions
20
examples/playbooks/rule-partial-become-without-become-pass.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
--- | ||
- hosts: localhost | ||
- name: Test play | ||
hosts: localhost | ||
become_user: root | ||
become: true | ||
|
||
tasks: | ||
- ansible.builtin.debug: | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: hello | ||
|
||
- hosts: localhost | ||
|
||
- name: Test play | ||
hosts: localhost | ||
tasks: | ||
- name: Foo | ||
ansible.builtin.command: whoami | ||
become_user: postgres | ||
become: true | ||
changed_when: false | ||
|
||
- hosts: localhost | ||
become: true | ||
- name: Test play | ||
hosts: localhost | ||
|
||
tasks: | ||
- name: Accepts a become from higher scope | ||
ansible.builtin.command: whoami | ||
become_user: postgres | ||
changed_when: false | ||
|
||
- hosts: localhost | ||
- name: Test play | ||
hosts: localhost | ||
become_user: postgres | ||
become: true | ||
|
||
tasks: | ||
- name: Accepts a become from a lower scope | ||
ansible.builtin.command: whoami | ||
become: true | ||
become_user: root | ||
changed_when: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
- name: Included with partial become | ||
ansible.builtin.debug: | ||
msg: Included with partial become |
56 changes: 56 additions & 0 deletions
56
examples/playbooks/transform-partial-become.transformed.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
# The play has become_user and the task has become | ||
# this is fixable, copy the become_user to the task | ||
# and remove from the play | ||
- name: Play 1 | ||
hosts: localhost | ||
tasks: | ||
- name: A block | ||
block: | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: hello | ||
become: true | ||
become_user: root | ||
|
||
# The task has become_user but the play does not | ||
# this is fixable, remove the become_user from the task | ||
- name: Play 2 | ||
hosts: localhost | ||
tasks: | ||
- name: A block | ||
block: | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: hello | ||
|
||
# The task has become_user and the play has become | ||
# this is fixable, add become to the task | ||
- name: Play 3 | ||
hosts: localhost | ||
become: true | ||
tasks: | ||
- name: A block | ||
block: | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: hello | ||
become: true | ||
become_user: root | ||
|
||
# The play has become_user but has an include | ||
# this is not fixable, the include could be called from multiple playbooks | ||
- name: Play 4 | ||
hosts: localhost | ||
become_user: root | ||
tasks: | ||
- name: A block | ||
block: | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: hello | ||
become: true | ||
|
||
- name: Include | ||
ansible.builtin.include_tasks: | ||
file: ../tasks/partial_become/main.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
# The play has become_user and the task has become | ||
# this is fixable, copy the become_user to the task | ||
# and remove from the play | ||
- name: Play 1 | ||
hosts: localhost | ||
become_user: root | ||
tasks: | ||
- name: A block | ||
block: | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: hello | ||
become: true | ||
|
||
# The task has become_user but the play does not | ||
# this is fixable, remove the become_user from the task | ||
- name: Play 2 | ||
hosts: localhost | ||
tasks: | ||
- name: A block | ||
block: | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: hello | ||
become_user: root | ||
|
||
# The task has become_user and the play has become | ||
# this is fixable, add become to the task | ||
- name: Play 3 | ||
hosts: localhost | ||
become: true | ||
tasks: | ||
- name: A block | ||
block: | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: hello | ||
become_user: root | ||
|
||
# The play has become_user but has an include | ||
# this is not fixable, the include could be called from multiple playbooks | ||
- name: Play 4 | ||
hosts: localhost | ||
become_user: root | ||
tasks: | ||
- name: A block | ||
block: | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: hello | ||
become: true | ||
|
||
- name: Include | ||
ansible.builtin.include_tasks: | ||
file: ../tasks/partial_become/main.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.