Skip to content

Commit

Permalink
Adopted more ansible.builtin.
Browse files Browse the repository at this point in the history
Related: ansible#1908
  • Loading branch information
ssbarnea committed Feb 18, 2022
1 parent 3eabeb8 commit 5a9fb2f
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 97 deletions.
4 changes: 2 additions & 2 deletions examples/playbooks/blockincludes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
- block:
# - include_tasks: "{{ varnotset }}.yml"
- block:
- include: "{{ varset }}.yml"
- ansible.builtin.include: "{{ varset }}.yml"
- block:
- include_tasks: "tasks/directory with spaces/main.yml"
- ansible.builtin.include_tasks: "tasks/directory with spaces/main.yml"
6 changes: 3 additions & 3 deletions examples/playbooks/blockincludes2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
varset: varset
tasks:
- block:
- include_tasks: tasks/nestedincludes.yml
- ansible.builtin.include_tasks: tasks/nestedincludes.yml
# - block:
# - include_tasks: "{{ varnotset }}.yml"
rescue:
- include_tasks: "{{ varset }}.yml"
- ansible.builtin.include_tasks: "{{ varset }}.yml"
always:
- include_tasks: "tasks/directory with spaces/main.yml"
- ansible.builtin.include_tasks: "tasks/directory with spaces/main.yml"
2 changes: 1 addition & 1 deletion examples/playbooks/common-include-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
gather_facts: false
tasks:
- name: some include
include: tasks/included-with-lint.yml
ansible.builtin.include: tasks/included-with-lint.yml
2 changes: 1 addition & 1 deletion examples/playbooks/include-in-block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
- hosts: all

tasks:
- include_tasks: tasks/include-in-block-inner.yml
- ansible.builtin.include_tasks: tasks/include-in-block-inner.yml
4 changes: 2 additions & 2 deletions examples/playbooks/playbook-imported.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
connection: local
gather_facts: false
tasks:
- command: echo "no name" # should generate unnamed-task
- ansible.builtin.command: echo "no name" # should generate unnamed-task
- name: Another task
debug:
ansible.builtin.debug:
msg: debug message
2 changes: 1 addition & 1 deletion examples/playbooks/playbook-parent.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
- name: Importing another playbook
import_playbook: playbook-imported.yml
ansible.builtin.import_playbook: playbook-imported.yml
2 changes: 1 addition & 1 deletion examples/playbooks/tasks/directory with spaces/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# this should generate: unnamed-task: All tasks should be named
- assert:
- ansible.builtin.assert:
fail_msg: tasks in directory with spaces included
2 changes: 1 addition & 1 deletion examples/playbooks/tasks/included-with-lint.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# missing a task name
- assert:
- ansible.builtin.assert:
fail_msg: foo
2 changes: 1 addition & 1 deletion examples/playbooks/tasks/passing_task.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
- name: Simple task to include which generates no errors
assert:
ansible.builtin.assert:
that: true
2 changes: 1 addition & 1 deletion examples/playbooks/tasks/simple_task.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# unnamed-task: All tasks should be named
- assert:
- ansible.builtin.assert:
fail_msg: foo
30 changes: 15 additions & 15 deletions examples/playbooks/var-spacing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
- hosts: all
tasks:
- name: good variable format
debug:
ansible.builtin.debug:
msg: "{{ good_format }}"
- name: good variable format
debug:
ansible.builtin.debug:
msg: "Value: {{ good_format }}"
- name: jinja escaping allowed
debug:
ansible.builtin.debug:
msg: "{{ '{{' }}"
- name: jinja escaping allowed
# noqa: 306
shell: docker info --format '{{ '{{' }}json .Swarm.LocalNodeState{{ '}}' }}' | tr -d '"'
ansible.builtin.shell: docker info --format '{{ '{{' }}json .Swarm.LocalNodeState{{ '}}' }}' | tr -d '"'
changed_when: false
- name: jinja whitespace control allowed
debug:
ansible.builtin.debug:
msg: |
{{ good_format }}/
{{- good_format }}
{{- good_format -}}
- name: bad variable format
debug:
ansible.builtin.debug:
msg: "{{bad_format}}"
- name: bad variable format
debug:
ansible.builtin.debug:
msg: "Value: {{ bad_format}}"
- name: bad variable format
debug:
ansible.builtin.debug:
msg: "{{bad_format }}"
- name: not a jinja variable # noqa var-spacing
debug:
ansible.builtin.debug:
# spell-checker: disable-next-line
msg: "data = ${lookup{$local_part}lsearch{/etc/aliases}}"
- name: JSON inside jinja is valid
debug:
ansible.builtin.debug:
msg: "{{ {'test': {'subtest': variable}} }}"
- name: Avoid false positive on multiline
vars:
Expand All @@ -45,26 +45,26 @@
case2: >-
http://example.com/{{
case2 }}
debug:
ansible.builtin.debug:
var: cases

- name: Valid single line nested JSON false positive
debug:
ansible.builtin.debug:
msg: "{{ {'dummy_2': {'nested_dummy_1': 'value_1', 'nested_dummy_2': value_2}} | combine(dummy_1) }}"

- name: Invalid single line nested JSON
debug:
ansible.builtin.debug:
msg: "{{ {'dummy_2': {'nested_dummy_1': 'value_1', 'nested_dummy_2': value_2}} | combine(dummy_1)}}"

- name: Valid multiline nested JSON false positive
debug:
ansible.builtin.debug:
msg: >-
{{ {'dummy_2': {'nested_dummy_1': value_1,
'nested_dummy_2': value_2}} |
combine(dummy_1) }}
- name: Invalid multiline nested JSON
debug:
ansible.builtin.debug:
msg: >-
{{ {'dummy_2': {'nested_dummy_1': value_1,
'nested_dummy_2': value_2}} |
Expand Down
10 changes: 5 additions & 5 deletions examples/roles/role_for_no_same_owner/tasks/pass.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
- name: synchronize-delegate
synchronize:
ansible.builtin.synchronize:
src: dummy
dest: dummy
delegate_to: localhost

- name: synchronize-no-same-owner
synchronize:
ansible.builtin.synchronize:
src: dummy
dest: dummy
owner: false
group: false

- name: unarchive-no-same-owner
unarchive:
ansible.builtin.unarchive:
src: "{{ file }}.tar.gz"
dest: dummy
extra_opts:
- "--no-same-owner"

- name: unarchive-remote-src
unarchive:
ansible.builtin.unarchive:
src: "{{ file }}.tar.gz"
dest: dummy
extra_opts:
- "--no-same-owner"

- name: unarchive-unknown-file-ending
unarchive:
ansible.builtin.unarchive:
src: "{{ file }}"
dest: "dummy"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# this task is missing a name (unnamed-task)
- ping:
- ansible.builtin.ping:
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# this task is missing a name (unnamed-task)
- ping:
- ansible.builtin.ping:
26 changes: 13 additions & 13 deletions src/ansiblelint/rules/UseCommandInsteadOfShellRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
- hosts: localhost
tasks:
- name: shell no pipe
shell: echo hello
ansible.builtin.shell: echo hello
changed_when: false
- name: shell with jinja filter
shell: echo {{ "hello"|upper }}
ansible.builtin.shell: echo {{ "hello"|upper }}
changed_when: false
- name: shell with jinja filter (fqcn)
Expand All @@ -48,47 +48,47 @@
- hosts: localhost
tasks:
- name: shell with pipe
shell: echo hello | true # noqa: risky-shell-pipe
ansible.builtin.shell: echo hello | true # noqa: risky-shell-pipe
changed_when: false
- name: shell with redirect
shell: echo hello > /tmp/hello
ansible.builtin.shell: echo hello > /tmp/hello
changed_when: false
- name: chain two shell commands
shell: echo hello && echo goodbye
ansible.builtin.shell: echo hello && echo goodbye
changed_when: false
- name: run commands in succession
shell: echo hello ; echo goodbye
ansible.builtin.shell: echo hello ; echo goodbye
changed_when: false
- name: use variables
shell: echo $HOME $USER
ansible.builtin.shell: echo $HOME $USER
changed_when: false
- name: use * for globbing
shell: ls foo*
ansible.builtin.shell: ls foo*
changed_when: false
- name: use ? for globbing
shell: ls foo?
ansible.builtin.shell: ls foo?
changed_when: false
- name: use [] for globbing
shell: ls foo[1,2,3]
ansible.builtin.shell: ls foo[1,2,3]
changed_when: false
- name: use shell generator
shell: ls foo{.txt,.xml}
ansible.builtin.shell: ls foo{.txt,.xml}
changed_when: false
- name: use backticks
shell: ls `ls foo*`
ansible.builtin.shell: ls `ls foo*`
changed_when: false
- name: use shell with cmd
shell:
ansible.builtin.shell:
cmd: |
set -x
ls foo?
Expand Down
4 changes: 2 additions & 2 deletions test/TestSkipImportPlaybook.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- hosts: all
tasks:
- name: success
fail: msg="fail"
ansible.builtin.fail: msg="fail"
when: false
"""

Expand All @@ -18,7 +18,7 @@
tasks:
- name: should be shell # noqa command-instead-of-shell no-changed-when
shell: echo lol
ansible.builtin.shell: echo lol
- import_playbook: imported_playbook.yml
"""
Expand Down
42 changes: 21 additions & 21 deletions test/TestSkipInsideYaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,68 @@

ROLE_TASKS = """\
---
- debug:
- ansible.builtin.debug:
msg: this should fail linting due lack of name
- debug: # noqa unnamed-task
- ansible.builtin.debug: # noqa unnamed-task
msg: this should pass due to noqa comment
"""

ROLE_TASKS_WITH_BLOCK = """\
---
- name: bad git 1 # noqa git-latest
action: git a=b c=d
action: ansible.builtin.git a=b c=d
- name: bad git 2
action: git a=b c=d
action: ansible.builtin.git a=b c=d
- name: Block with rescue and always section
block:
- name: bad git 3 # noqa git-latest
action: git a=b c=d
action: ansible.builtin.git a=b c=d
- name: bad git 4
action: git a=b c=d
action: ansible.builtin.git a=b c=d
rescue:
- name: bad git 5 # noqa git-latest
action: git a=b c=d
action: ansible.builtin.git a=b c=d
- name: bad git 6
action: git a=b c=d
action: ansible.builtin.git a=b c=d
always:
- name: bad git 7 # noqa git-latest
action: git a=b c=d
action: ansible.builtin.git a=b c=d
- name: bad git 8
action: git a=b c=d
action: ansible.builtin.git a=b c=d
"""

PLAYBOOK = """\
- hosts: all
tasks:
- name: test hg-latest
action: hg
action: ansible.builtin.hg
- name: test hg-latest (skipped) # noqa hg-latest
action: hg
action: ansible.builtin.hg
- name: test git-latest and partial-become
become_user: alice
action: git
action: ansible.builtin.git
- name: test git-latest and partial-become (skipped) # noqa git-latest partial-become
become_user: alice
action: git
action: ansible.builtin.git
- name: test YAML and var-spacing
get_url:
ansible.builtin.get_url:
url: http://example.com/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/file.conf
dest: "{{dest_proj_path}}/foo.conf"
- name: test YAML and var-spacing (skipped)
get_url:
ansible.builtin.get_url:
url: http://example.com/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/file.conf # noqa yaml
dest: "{{dest_proj_path}}/foo.conf" # noqa var-spacing
- name: test deprecated-command-syntax
command: creates=B chmod 644 A
ansible.builtin.command: creates=B chmod 644 A
- name: test deprecated-command-syntax
command: warn=yes creates=B chmod 644 A
ansible.builtin.command: warn=yes creates=B chmod 644 A
- name: test deprecated-command-syntax (skipped via no warn)
command: warn=no creates=B chmod 644 A
ansible.builtin.command: warn=no creates=B chmod 644 A
- name: test deprecated-command-syntax (skipped via skip_ansible_lint)
command: creates=B chmod 644 A
ansible.builtin.command: creates=B chmod 644 A
tags:
- skip_ansible_lint
"""
Expand All @@ -85,7 +85,7 @@
block:
- name: bar
become_user: john_doe
command: "/etc/test.sh"
ansible.builtin.command: "/etc/test.sh"
changed_when: false
"""

Expand Down
Loading

0 comments on commit 5a9fb2f

Please sign in to comment.