From a5e1b65756dfb805c9a65dfb34e774dce2d32f1e Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Tue, 23 Oct 2018 11:03:09 +0100 Subject: [PATCH] Only set Ironic port attributes when changed This fixes a lint issue: [301] Commands should not change things if nothing needs doing /home/will/code/tenks/ansible/roles/ironic-enrolment/tasks/port.yml:20 Task/Handler: Set Ironic port attributes TrivialFix Change-Id: I7940fe25d3518daf268484e292e337abc925080d --- ansible/roles/ironic-enrolment/tasks/port.yml | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/ansible/roles/ironic-enrolment/tasks/port.yml b/ansible/roles/ironic-enrolment/tasks/port.yml index acbfea2..eb1c5c6 100644 --- a/ansible/roles/ironic-enrolment/tasks/port.yml +++ b/ansible/roles/ironic-enrolment/tasks/port.yml @@ -17,14 +17,30 @@ set_fact: bridge: "{{ physnet | bridge_name }}" +- name: Get existing Ironic port attributes + command: >- + {{ ironic_virtualenv_path }}/bin/openstack baremetal port show + {{ uuid.stdout }} -f json + register: port_attributes_output + changed_when: false + - name: Set Ironic port attributes + vars: + port_attributes: "{{ port_attributes_output.stdout | from_json }}" + switch_id: "{{ hostvars[ironic_hypervisor]['ansible_' + bridge].macaddress }}" + switch_info: "{{ bridge }}" + port_id: >- + {{ source_interface + | source_to_ovs_link_name(inventory_hostname=ironic_hypervisor) }} command: >- '{{ ironic_virtualenv_path }}/bin/openstack' baremetal port set {{ uuid.stdout }} --physical-network '{{ physnet }}' - --local-link-connection switch_id='{{ hostvars[ironic_hypervisor][ - 'ansible_' + bridge - ].macaddress }}' + --local-link-connection switch_id='{{ switch_id }}' --local-link-connection switch_info='{{ bridge }}' - --local-link-connection port_id='{{ source_interface - | source_to_ovs_link_name(inventory_hostname=ironic_hypervisor) }}' + --local-link-connection port_id='{{ port_id }}' + when: >- + port_attributes.physical_network != physnet or + port_attributes.local_link_connection.switch_id != switch_id or + port_attributes.local_link_connection.switch_info != switch_info or + port_attributes.local_link_connection.port_id != port_id