Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions etc/kayobe/ansible/maintenance/octavia-amphora-image-register.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,38 +85,37 @@
register: image_info
delegate_to: "{{ groups['controllers'][0] }}"

- name: Ensure old Octavia Amphora image is renamed
vars:
ansible_python_interpreter: "{{ venv }}/bin/python"
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
ansible.builtin.command:
cmd: >-
{{ venv }}/bin/openstack image set amphora-x64-haproxy --name amphora-x64-haproxy-{{ ansible_facts.date_time.iso8601_basic_short }}
when:
- image_info.images | length != 0
- image_info.images[0].checksum != image_checksum.stat.checksum
changed_when: true
environment: "{{ openstack_auth_env }}"
delegate_to: "{{ groups['controllers'][0] }}"
- when: image_info.images | selectattr("name", "equalto", "amphora-x64-haproxy") | selectattr("checksum", "equalto", image_checksum.stat.checksum) | list | length == 0

Check failure on line 88 in etc/kayobe/ansible/maintenance/octavia-amphora-image-register.yml

View workflow job for this annotation

GitHub Actions / Ansible 2.18 lint with Python 3.12

name[missing]

All tasks should be named.

Check failure on line 88 in etc/kayobe/ansible/maintenance/octavia-amphora-image-register.yml

View workflow job for this annotation

GitHub Actions / Ansible 2.17 lint with Python 3.10

name[missing]

All tasks should be named.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The selectattr filter for the image name is redundant here because the openstack.cloud.image_info task at line 79 already filters the results by the name amphora-x64-haproxy. Removing it makes the condition more concise and easier to read.

    - when: image_info.images | selectattr("checksum", "equalto", image_checksum.stat.checksum) | list | length == 0

block:
- name: Ensure old Octavia Amphora image is renamed
vars:
ansible_python_interpreter: "{{ venv }}/bin/python"
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
ansible.builtin.command:
cmd: >-
{{ venv }}/bin/openstack image set amphora-x64-haproxy --name amphora-x64-haproxy-{{ ansible_facts.date_time.iso8601_basic_short }}
changed_when: true
environment: "{{ openstack_auth_env }}"
delegate_to: "{{ groups['controllers'][0] }}"
when: image_info.images | selectattr("name", "equalto", "amphora-x64-haproxy") | list | length == 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The name filter is redundant here as well, as the image_info results are already filtered by name. You can simplify this to check the length of the images list directly.

          when: image_info.images | length == 1


- name: Ensure new Octavia Amphora image is registered
vars:
ansible_python_interpreter: "{{ venv }}/bin/python"
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
openstack.cloud.image:
auth_type: password
auth: "{{ openstack_auth }}"
ca_cert: "{{ openstack_cacert }}"
interface: "{{ openstack_interface }}"
name: amphora-x64-haproxy
tags: ["amphora"]
container_format: bare
disk_format: qcow2
is_public: false
filename: "{{ image_path }}"
properties:
hw_architecture: x86_64
hw_rng_model: virtio
when: image_info.images | length == 0 or (image_info.images | length != 0 and image_info.images[0].checksum != image_checksum.stat.checksum)
become: true
delegate_to: "{{ groups['controllers'][0] }}"
- name: Ensure new Octavia Amphora image is registered
vars:
ansible_python_interpreter: "{{ venv }}/bin/python"
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
openstack.cloud.image:
auth_type: password
auth: "{{ openstack_auth }}"
ca_cert: "{{ openstack_cacert }}"
interface: "{{ openstack_interface }}"
name: amphora-x64-haproxy
tags: ["amphora"]
container_format: bare
disk_format: qcow2
is_public: false
filename: "{{ image_path }}"
properties:
hw_architecture: x86_64
hw_rng_model: virtio
become: true
delegate_to: "{{ groups['controllers'][0] }}"
Loading