Skip to content

Commit

Permalink
ansible-lint - use changed_when for conditional tasks; add line lengt…
Browse files Browse the repository at this point in the history
…h comment (#344)

* ansible-lint - use changed_when for conditional tasks; add line length comment

ansible-lint now requires the use of changed_when even for
conditional tasks

Add yamllint line-length suppression

Fix jinja spacing

Use descriptive task names

Signed-off-by: Rich Megginson <rmeggins@redhat.com>

* fix exception/error message checking

* ansible 2.9 errors are in a different variable

---------

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
  • Loading branch information
richm authored Apr 13, 2023
1 parent 01781d5 commit 7126d8d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
5 changes: 3 additions & 2 deletions tasks/enable_copr.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
- name: Make sure COPR is not already enabled
- name: Get list of COPRs
shell: |
set -euo pipefail
{{ ansible_pkg_mgr }} repolist | \
grep -c `echo {{ repo.repository }} | tr / :` || true
register: copr_present
changed_when: false

- name: Get list of COPRs to be enabled
- name: Enable COPRs
command:
cmd: "{{ ansible_pkg_mgr }} -y copr enable {{ repo.repository }}"
when: copr_present.stdout == "0"
changed_when: true
6 changes: 3 additions & 3 deletions tasks/enable_coprs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
when:
- _storage_copr_packages is defined
- copr_packages is defined
- repo.packages|intersect(copr_packages)|length
- repo.packages | intersect(copr_packages) | length > 0

- name: Make sure COPR support packages are present
package:
name: "{{ _storage_copr_support_packages }}"
when: install_copr is defined and install_copr | bool
when: install_copr | d(false) | bool

- name: Enable COPRs
include_tasks: enable_copr.yml
Expand All @@ -23,4 +23,4 @@
when:
- _storage_copr_packages is defined
- copr_packages is defined
- repo.packages | intersect(copr_packages) | length
- repo.packages | intersect(copr_packages) | length > 0
3 changes: 2 additions & 1 deletion tests/verify-pool-member-lvmraid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
- storage_test_lvmraid_volume.state != "absent"
block:
- name: Get information about LVM RAID
# noqa yaml[line-length]
# yamllint disable rule:line-length
command: >-
lvs --noheading -o lv_name --select
'lv_name={{ storage_test_lvmraid_volume.name }}&&lv_layout={{ storage_test_lvmraid_volume.raid_level }}'
{{ storage_test_pool.name }}
register: storage_test_lvmraid_status
changed_when: false
# yamllint enable rule:line-length

- name: Check that volume is LVM RAID
assert:
Expand Down
28 changes: 13 additions & 15 deletions tests/verify-role-failed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@
- __storage_failed_regex is defined
- __storage_failed_msg is defined

- name: Verify module raised the correct exception
- name: Verify correct exception or error message
assert:
that: ansible_failed_result.msg.exception is
search(__storage_failed_exception)
when:
- __storage_failed_exception is defined
- ansible_failed_result.msg.exception is defined

- name: Verify module raised the correct exception
assert:
that: ansible_failed_result.msg.module_stdout is
search(__storage_failed_exception)
when:
- __storage_failed_exception is defined
- not ansible_failed_result.msg.exception is defined
- ansible_failed_result.msg.module_stdout is defined
that: exception is search(__storage_failed_exception) or
msg_stdout is search(__storage_failed_exception) or
msg_stderr is search(__storage_failed_exception) or
stdout is search(__storage_failed_exception) or
stderr is search(__storage_failed_exception)
when: __storage_failed_exception is defined
vars:
exception: "{{ ansible_failed_result.msg.exception | d('') }}"
msg_stdout: "{{ ansible_failed_result.msg.module_stdout | d('') }}"
msg_stderr: "{{ ansible_failed_result.msg.module_stderr | d('') }}"
stdout: "{{ ansible_failed_result.module_stdout | d('') }}"
stderr: "{{ ansible_failed_result.module_stderr | d('') }}"

0 comments on commit 7126d8d

Please sign in to comment.