From 4d26e4acd9c9568b72aada67afb98515b5b3e172 Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Fri, 15 Jul 2016 04:46:38 -0500 Subject: [PATCH] Check host group_names for group membership If a task only applies when a host is a member of a particular group, check for the group in a host's 'group_names' rather than checking for the name of the host in the group itself. These are functionally the same check but, for the latter, a fatal error can occur if any particular group does not exist at all within the environment. Change-Id: Ib64ae9454e228da2ea37bc6d2760857f399ccade --- tasks/main.yml | 12 +++++++----- tasks/neutron_init.yml | 19 +++++++++---------- tasks/neutron_install-apt.yml | 6 ++---- tasks/neutron_post_install.yml | 8 ++++---- tasks/nuage_neutron_config.yml | 2 +- tasks/plumgrid_config.yml | 4 ++-- templates/neutron.conf.j2 | 2 +- 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 597ea98a..520b3332 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -63,20 +63,22 @@ - neutron-install - include: neutron_db_setup.yml - when: > - inventory_hostname == groups[neutron_services['neutron-server']['group']][0] + when: + - neutron_services['neutron-server']['group'] in group_names + - inventory_hostname == groups[neutron_services['neutron-server']['group']][0] tags: - neutron-install - include: neutron_service_setup.yml - when: > - inventory_hostname == groups['neutron_all'][0] + when: + - "'neutron_all' in group_names" + - inventory_hostname == groups['neutron_all'][0] tags: - neutron-install - include: neutron_l3_ha.yml when: - - inventory_hostname in groups[neutron_services['neutron-l3-agent']['group']] + - neutron_services['neutron-l3-agent']['group'] in group_names - neutron_legacy_ha_tool_enabled | bool - name: Flush handlers diff --git a/tasks/neutron_init.yml b/tasks/neutron_init.yml index 6a2be792..ca4f699c 100644 --- a/tasks/neutron_init.yml +++ b/tasks/neutron_init.yml @@ -22,7 +22,7 @@ system_group: "{{ neutron_system_group_name }}" service_home: "{{ neutron_system_home_folder }}" when: - - inventory_hostname in groups[neutron_services['neutron-server']['group']] + - neutron_services['neutron-server']['group'] in group_names - neutron_services['neutron-server'].service_en | bool - include: neutron_init_common.yml @@ -34,7 +34,7 @@ system_group: "{{ neutron_system_group_name }}" service_home: "{{ neutron_system_home_folder }}" when: - - inventory_hostname in groups[neutron_services['neutron-dhcp-agent']['group']] + - neutron_services['neutron-dhcp-agent']['group'] in group_names - neutron_services['neutron-dhcp-agent'].service_en | bool - include: neutron_init_common.yml @@ -46,7 +46,7 @@ system_group: "{{ neutron_system_group_name }}" service_home: "{{ neutron_system_home_folder }}" when: - - inventory_hostname in groups[neutron_services['neutron-l3-agent']['group']] + - neutron_services['neutron-l3-agent']['group'] in group_names - neutron_services['neutron-l3-agent'].service_en | bool - include: neutron_init_common.yml @@ -58,7 +58,7 @@ system_group: "{{ neutron_system_group_name }}" service_home: "{{ neutron_system_home_folder }}" when: - - inventory_hostname in groups[neutron_services['neutron-linuxbridge-agent']['group']] + - neutron_services['neutron-linuxbridge-agent']['group'] in group_names - neutron_services['neutron-linuxbridge-agent'].service_en | bool - include: neutron_init_common.yml @@ -71,7 +71,6 @@ service_home: "{{ neutron_system_home_folder }}" when: - neutron_services['neutron-openvswitch-agent']['group'] in group_names - - inventory_hostname in groups[neutron_services['neutron-openvswitch-agent']['group']] - neutron_services['neutron-openvswitch-agent'].service_en | bool - include: neutron_init_common.yml @@ -83,7 +82,7 @@ system_group: "{{ neutron_system_group_name }}" service_home: "{{ neutron_system_home_folder }}" when: - - inventory_hostname in groups[neutron_services['neutron-metadata-agent']['group']] + - neutron_services['neutron-metadata-agent']['group'] in group_names - neutron_services['neutron-metadata-agent'].service_en | bool - include: neutron_init_common.yml @@ -95,7 +94,7 @@ system_group: "{{ neutron_system_group_name }}" service_home: "{{ neutron_system_home_folder }}" when: - - inventory_hostname in groups[neutron_services['neutron-metering-agent']['group']] + - neutron_services['neutron-metering-agent']['group'] in group_names - neutron_services['neutron-metering-agent'].service_en | bool - include: neutron_init_common.yml @@ -107,7 +106,7 @@ system_group: "{{ neutron_system_group_name }}" service_home: "{{ neutron_system_home_folder }}" when: - - inventory_hostname in groups[neutron_services['neutron-lbaas-agent']['group']] + - neutron_services['neutron-lbaas-agent']['group'] in group_names - neutron_services['neutron-lbaas-agent'].service_en | bool - include: neutron_init_common.yml @@ -119,7 +118,7 @@ system_group: "{{ neutron_system_group_name }}" service_home: "{{ neutron_system_home_folder }}" when: - - inventory_hostname in groups[neutron_services['neutron-lbaasv2-agent']['group']] + - neutron_services['neutron-lbaasv2-agent']['group'] in group_names - neutron_services['neutron-lbaasv2-agent'].service_en | bool - include: neutron_init_common.yml @@ -131,5 +130,5 @@ system_group: "{{ neutron_system_group_name }}" service_home: "{{ neutron_system_home_folder }}" when: - - inventory_hostname in groups[neutron_services['neutron-vpnaas-agent']['group']] + - neutron_services['neutron-vpnaas-agent']['group'] in group_names - neutron_services['neutron-vpnaas-agent'].service_en | bool diff --git a/tasks/neutron_install-apt.yml b/tasks/neutron_install-apt.yml index dfe99e9e..08c69ecb 100644 --- a/tasks/neutron_install-apt.yml +++ b/tasks/neutron_install-apt.yml @@ -61,7 +61,6 @@ delay: 2 with_items: "{{ neutron_lxb_apt_packages }}" when: - - inventory_hostname in groups[neutron_services['neutron-linuxbridge-agent']['group']] - neutron_services['neutron-linuxbridge-agent']['group'] in group_names - neutron_services['neutron-linuxbridge-agent'].service_en | bool @@ -75,7 +74,6 @@ delay: 2 with_items: "{{ ovs_apt_packages }}" when: - - inventory_hostname in groups[neutron_services['neutron-openvswitch-agent']['group']] - neutron_services['neutron-openvswitch-agent']['group'] in group_names - neutron_services['neutron-openvswitch-agent'].service_en | bool @@ -89,7 +87,7 @@ delay: 2 with_items: "{{ neutron_lbaas_apt_packages }}" when: - - inventory_hostname in groups[neutron_services['neutron-lbaas-agent']['group']] + - neutron_services['neutron-lbaas-agent']['group'] in group_names - neutron_lbaas | bool or neutron_lbaasv2 | bool - name: Install apt packages for VPNaaS @@ -102,7 +100,7 @@ delay: 2 with_items: "{{ neutron_vpnaas_apt_packages }}" when: - - inventory_hostname in groups[neutron_services['neutron-vpnaas-agent']['group']] + - neutron_services['neutron-vpnaas-agent']['group'] in group_names - neutron_vpnaas | bool - name: remove specific apt packages diff --git a/tasks/neutron_post_install.yml b/tasks/neutron_post_install.yml index 2f223f32..7918d0ae 100644 --- a/tasks/neutron_post_install.yml +++ b/tasks/neutron_post_install.yml @@ -60,7 +60,7 @@ notify: - Restart neutron services when: > - inventory_hostname in groups[neutron_services['neutron-dhcp-agent']['group']] + neutron_services['neutron-dhcp-agent']['group'] in group_names - name: Generate neutron agent only Config config_template: @@ -77,7 +77,7 @@ when: - item.value.service_en | bool - item.value.service_conf is defined - - inventory_hostname in groups[item.value.group] + - item.value.group in group_names - name: Drop neutron rootwrap filters copy: @@ -129,10 +129,10 @@ mode: "0755" when: - neutron_metadata_checksum_fix | bool - - inventory_hostname in groups[neutron_services['neutron-linuxbridge-agent']['group']] + - neutron_services['neutron-linuxbridge-agent']['group'] in group_names - name: Run metadata iptables checksum fix command: /etc/network/if-up.d/post-up-metadata-checksum when: - neutron_metadata_checksum_fix | bool - - inventory_hostname in groups[neutron_services['neutron-linuxbridge-agent']['group']] + - neutron_services['neutron-linuxbridge-agent']['group'] in group_names diff --git a/tasks/nuage_neutron_config.yml b/tasks/nuage_neutron_config.yml index c5c194fe..994a62be 100644 --- a/tasks/nuage_neutron_config.yml +++ b/tasks/nuage_neutron_config.yml @@ -23,4 +23,4 @@ with_items: - "{{ neutron_proprietary_nuage_pip_packages }}" when: - - inventory_hostname in groups[neutron_services['neutron-server']['group']] + - neutron_services['neutron-server']['group'] in group_names diff --git a/tasks/plumgrid_config.yml b/tasks/plumgrid_config.yml index 21753fe8..d8d9aea0 100644 --- a/tasks/plumgrid_config.yml +++ b/tasks/plumgrid_config.yml @@ -43,7 +43,7 @@ with_items: - "{{ neutron_optional_plumgrid_pip_packages }}" when: - - inventory_hostname in groups[neutron_services['neutron-server']['group']] + - neutron_services['neutron-server']['group'] in group_names - name: Install plumgrid pip packages fall back pip: @@ -60,4 +60,4 @@ - "{{ neutron_optional_plumgrid_pip_packages }}" when: - install_packages | failed - - inventory_hostname in groups[neutron_services['neutron-server']['group']] + - neutron_services['neutron-server']['group'] in group_names diff --git a/templates/neutron.conf.j2 b/templates/neutron.conf.j2 index f67b2eca..ff4cad00 100644 --- a/templates/neutron.conf.j2 +++ b/templates/neutron.conf.j2 @@ -9,7 +9,7 @@ debug = {{ debug }} fatal_deprecations = {{ neutron_fatal_deprecations }} log_file = /var/log/neutron/neutron.log -{% if inventory_hostname in groups[neutron_services['neutron-server']['group']] %} +{% if neutron_services['neutron-server']['group'] in group_names %} # General, only applies to neutron server host group allow_overlapping_ips = True