From 059d84859f29c4950e9aab78e753e38ed0ed8706 Mon Sep 17 00:00:00 2001 From: Swapnil Kulkarni Date: Tue, 11 Aug 2015 06:38:49 +0000 Subject: [PATCH] Remove Ansible abstraction for Neutron Co-Authored-By: Sam Yaple Change-Id: I19ae5c2d58b94cd95b969e5c4e65ef1670a78b7e Partially-Implements: blueprint remove-abstraction-ansible --- ansible/roles/neutron/defaults/main.yml | 52 +++----- ansible/roles/neutron/tasks/bootstrap.yml | 68 ++++++++-- ansible/roles/neutron/tasks/start.yml | 156 +++++++++++++++------- 3 files changed, 184 insertions(+), 92 deletions(-) diff --git a/ansible/roles/neutron/defaults/main.yml b/ansible/roles/neutron/defaults/main.yml index 22475f2051..e05869c38f 100644 --- a/ansible/roles/neutron/defaults/main.yml +++ b/ansible/roles/neutron/defaults/main.yml @@ -8,49 +8,33 @@ neutron_database_name: "neutron" neutron_database_user: "neutron" neutron_database_address: "{{ kolla_internal_address }}" -# Do not override "service_*" variables -service_database_name: "{{ neutron_database_name }}" -service_database_user: "{{ neutron_database_user }}" -service_database_password: "{{ neutron_database_password }}" - #################### # Docker #################### -docker_neutron_registry: "{{ docker_registry ~ '/' if docker_registry else '' }}" -docker_neutron_namespace: "{{ docker_namespace }}" -kolla_neutron_base_distro: "{{ kolla_base_distro }}" -kolla_neutron_install_type: "{{ kolla_install_type }}" +neutron_server_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-neutron-server" +neutron_server_tag: "{{ openstack_release }}" +neutron_server_image_full: "{{ neutron_server_image }}:{{ neutron_server_tag }}" -kolla_neutron_server_container_name: "neutron-server" -docker_neutron_server_image: "{{ docker_neutron_registry }}{{ docker_neutron_namespace }}/{{ kolla_neutron_base_distro }}-{{ kolla_neutron_install_type }}-{{ kolla_neutron_server_container_name }}" -docker_neutron_server_tag: "{{ openstack_release }}" -docker_neutron_server_image_full: "{{ docker_neutron_server_image }}:{{ docker_neutron_server_tag }}" +neutron_agents_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-neutron-agents" +neutron_agents_tag: "{{ openstack_release }}" +neutron_agents_image_full: "{{ neutron_agents_image }}:{{ neutron_agents_tag }}" -kolla_neutron_agents_container_name: "neutron-agents" -docker_neutron_agents_image: "{{ docker_neutron_registry }}{{ docker_neutron_namespace }}/{{ kolla_neutron_base_distro }}-{{ kolla_neutron_install_type }}-{{ kolla_neutron_agents_container_name }}" -docker_neutron_agents_tag: "{{ openstack_release }}" -docker_neutron_agents_image_full: "{{ docker_neutron_agents_image }}:{{ docker_neutron_agents_tag }}" +neutron_openvswitch_agent_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-neutron-openvswitch-agent" +neutron_openvswitch_agent_tag: "{{ openstack_release }}" +neutron_openvswitch_agent_image_full: "{{ neutron_openvswitch_agent_image }}:{{ neutron_openvswitch_agent_tag }}" -kolla_neutron_openvswitch_agent_container_name: "neutron-openvswitch-agent" -docker_neutron_openvswitch_agent_image: "{{ docker_neutron_registry }}{{ docker_neutron_namespace }}/{{ kolla_neutron_base_distro }}-{{ kolla_neutron_install_type }}-{{ kolla_neutron_openvswitch_agent_container_name }}" -docker_neutron_openvswitch_agent_tag: "{{ openstack_release }}" -docker_neutron_openvswitch_agent_image_full: "{{ docker_neutron_openvswitch_agent_image }}:{{ docker_neutron_openvswitch_agent_tag }}" +neutron_linuxbridge_agent_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-neutron-linuxbridge-agent" +neutron_linuxbridge_agent_tag: "{{ openstack_release }}" +neutron_linuxbridge_agent_image_full: "{{ neutron_linuxbridge_agent_image }}:{{ neutron_linuxbridge_agent_tag }}" -kolla_neutron_linuxbridge_agent_container_name: "neutron-linuxbridge-agent" -docker_neutron_linuxbridge_agent_image: "{{ docker_neutron_registry }}{{ docker_neutron_namespace }}/{{ kolla_neutron_base_distro }}-{{ kolla_neutron_install_type }}-{{ kolla_neutron_linuxbridge_agent_container_name }}" -docker_neutron_linuxbridge_agent_tag: "{{ openstack_release }}" -docker_neutron_linuxbridge_agent_image_full: "{{ docker_neutron_linuxbridge_agent_image }}:{{ docker_neutron_linuxbridge_agent_tag }}" +openvswitch_vswitchd_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-ovs-vswitchd" +openvswitch_vswitchd_tag: "{{ openstack_release }}" +openvswitch_vswitchd_image_full: "{{ openvswitch_vswitchd_image }}:{{ openvswitch_vswitchd_tag }}" -kolla_openvswitch_db_container_name: "ovs-db-server" -docker_openvswitch_db_image: "{{ docker_neutron_registry }}{{ docker_neutron_namespace }}/{{ kolla_neutron_base_distro }}-{{ kolla_neutron_install_type }}-{{ kolla_openvswitch_db_container_name }}" -docker_openvswitch_db_tag: "{{ openstack_release }}" -docker_openvswitch_db_image_full: "{{ docker_openvswitch_db_image }}:{{ docker_openvswitch_db_tag }}" - -kolla_openvswitch_vswitchd_container_name: "ovs-vswitchd" -docker_openvswitch_vswitchd_image: "{{ docker_neutron_registry }}{{ docker_neutron_namespace }}/{{ kolla_neutron_base_distro }}-{{ kolla_neutron_install_type }}-{{ kolla_openvswitch_vswitchd_container_name }}" -docker_openvswitch_vswitchd_tag: "{{ openstack_release }}" -docker_openvswitch_vswitchd_image_full: "{{ docker_openvswitch_vswitchd_image }}:{{ docker_openvswitch_vswitchd_tag }}" +openvswitch_db_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-ovs-db-server" +openvswitch_db_tag: "{{ openstack_release }}" +openvswitch_db_image_full: "{{ openvswitch_db_image }}:{{ openvswitch_db_tag }}" #################### diff --git a/ansible/roles/neutron/tasks/bootstrap.yml b/ansible/roles/neutron/tasks/bootstrap.yml index f0e9aabcd5..74a51b60b8 100644 --- a/ansible/roles/neutron/tasks/bootstrap.yml +++ b/ansible/roles/neutron/tasks/bootstrap.yml @@ -1,12 +1,62 @@ --- -- include: ../../bootstrap.yml - vars: - container_detach: False - container_environment: +- name: Creating Neutron database + command: docker exec -t kolla_ansible /usr/bin/ansible localhost + -m mysql_db + -a "login_host='{{ database_address }}' + login_user='{{ database_user }}' + login_password='{{ database_password }}' + name='{{ neutron_database_name }}'" + register: database + changed_when: "{{ database.stdout.find('localhost | SUCCESS => ') != -1 and (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" + failed_when: database.stdout.split()[2] != 'SUCCESS' + run_once: True + +- name: Creating Neutron database user and setting permissions + command: docker exec -t kolla_ansible /usr/bin/ansible localhost + -m mysql_user + -a "login_host='{{ database_address }}' + login_user='{{ database_user }}' + login_password='{{ database_password }}' + name='{{ neutron_database_name }}' + password='{{ neutron_database_password }}' + host='%' + priv='{{ neutron_database_name }}.*:ALL' + append_privs='yes'" + register: database_user + changed_when: "{{ database.stdout.find('localhost | SUCCESS => ') != -1 and (database_user.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" + failed_when: database_user.stdout.split()[2] != 'SUCCESS' + run_once: True + +- name: Starting Neutron bootstrap container + docker: + detach: False + docker_api_version: "{{ docker_api_version }}" + net: host + pull: "{{ docker_pull_policy }}" + restart_policy: "no" + state: reloaded + registry: "{{ docker_registry }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + insecure_registry: "{{ docker_insecure_registry }}" + name: bootstrap_neutron + image: "{{ neutron_server_image_full }}" + volumes: "{{ node_config_directory }}/neutron-server/:/opt/kolla/neutron-server/:ro" + env: KOLLA_BOOTSTRAP: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - container_image: "{{ docker_neutron_server_image_full }}" - container_name: "bootstrap_neutron" - container_restart_policy: "no" - container_volumes: - - "{{ node_config_directory }}/neutron-server/:/opt/kolla/neutron-server/:ro" + run_once: True + when: database.stdout.find('localhost | SUCCESS => ') != -1 and (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed + +# https://github.com/ansible/ansible-modules-core/pull/1031 + +- name: Waiting for bootstrap container to exit + command: docker wait bootstrap_neutron + when: database.stdout.find('localhost | SUCCESS => ') != -1 and (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed + +- name: Cleaning up Neutron boostrap container + docker: + name: bootstrap_neutron + image: "{{ neutron_server_image_full }}" + state: absent + when: database.stdout.find('localhost | SUCCESS => ') != -1 and (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed diff --git a/ansible/roles/neutron/tasks/start.yml b/ansible/roles/neutron/tasks/start.yml index dd85eea2d6..e3e9086271 100644 --- a/ansible/roles/neutron/tasks/start.yml +++ b/ansible/roles/neutron/tasks/start.yml @@ -1,25 +1,45 @@ --- -- include: ../../start.yml - vars: - container_environment: - KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - container_image: "{{ docker_openvswitch_db_image_full }}" - container_name: "openvswitch_db" - container_volumes: +- name: Starting Openvswitch-db container + docker: + docker_api_version: "{{ docker_api_version }}" + net: host + pull: "{{ docker_pull_policy }}" + restart_policy: "{{ docker_restart_policy }}" + restart_policy_retry: "{{ docker_restart_policy_retry }}" + state: reloaded + registry: "{{ docker_registry }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + insecure_registry: "{{ docker_insecure_registry }}" + name: openvswitch_db + image: "{{ openvswitch_db_image_full }}" + volumes: - "/run:/run" + env: + KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" when: (inventory_hostname in groups['compute'] or inventory_hostname in groups['neutron-agents']) and neutron_plugin_agent == "openvswitch" -- include: ../../start.yml - vars: - container_environment: - KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - container_image: "{{ docker_openvswitch_vswitchd_image_full }}" - container_name: "openvswitch_vswitchd" - container_privileged: "True" - container_volumes: +- name: Starting Openvswitch-vswitchd container + docker: + docker_api_version: "{{ docker_api_version }}" + net: host + pull: "{{ docker_pull_policy }}" + restart_policy: "{{ docker_restart_policy }}" + restart_policy_retry: "{{ docker_restart_policy_retry }}" + state: reloaded + registry: "{{ docker_registry }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + insecure_registry: "{{ docker_insecure_registry }}" + privileged: True + name: openvswitch_vswitchd + image: "{{ openvswitch_vswitchd_image_full }}" + volumes: - "/run:/run" - "/lib/modules:/lib/modules:ro" + env: + KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" when: (inventory_hostname in groups['compute'] or inventory_hostname in groups['neutron-agents']) and neutron_plugin_agent == "openvswitch" @@ -30,55 +50,93 @@ when: (inventory_hostname in groups['compute'] or inventory_hostname in groups['neutron-agents']) and neutron_plugin_agent == "openvswitch" -- include: ../../start.yml - vars: - container_environment: +- name: Starting Neutron-server container + docker: + docker_api_version: "{{ docker_api_version }}" + net: host + pull: "{{ docker_pull_policy }}" + restart_policy: "{{ docker_restart_policy }}" + restart_policy_retry: "{{ docker_restart_policy_retry }}" + state: reloaded + registry: "{{ docker_registry }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + insecure_registry: "{{ docker_insecure_registry }}" + name: neutron_server + image: "{{ neutron_server_image_full }}" + volumes: "{{ node_config_directory }}/neutron-server/:/opt/kolla/neutron-server/:ro" + env: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - container_image: "{{ docker_neutron_server_image_full }}" - container_name: "neutron_server" - container_volumes: - - "{{ node_config_directory }}/neutron-server/:/opt/kolla/neutron-server/:ro" when: inventory_hostname in groups['neutron-server'] -- include: ../../start.yml - vars: - container_environment: - KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - container_image: "{{ docker_neutron_openvswitch_agent_image_full }}" - container_name: "neutron_openvswitch_agent" - container_privileged: "True" - container_volumes: +- name: Starting Neutron-openvswitch-agent container + docker: + docker_api_version: "{{ docker_api_version }}" + net: host + pull: "{{ docker_pull_policy }}" + restart_policy: "{{ docker_restart_policy }}" + restart_policy_retry: "{{ docker_restart_policy_retry }}" + state: reloaded + registry: "{{ docker_registry }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + insecure_registry: "{{ docker_insecure_registry }}" + privileged: True + name: neutron_openvswitch_agent + image: "{{ neutron_openvswitch_agent_image_full }}" + volumes: - "/run:/run" - "/lib/modules:/lib/modules:ro" - "{{ node_config_directory }}/neutron-openvswitch-agent/:/opt/kolla/neutron-openvswitch-agent/:ro" + env: + KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" when: (inventory_hostname in groups['compute'] or inventory_hostname in groups['neutron-agents']) and neutron_plugin_agent == "openvswitch" -- include: ../../start.yml - vars: - container_environment: - KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - NEUTRON_BRIDGE: "br-ex" - NEUTRON_INTERFACE: "{{ neutron_external_interface }}" - container_image: "{{ docker_neutron_linuxbridge_agent_image_full }}" - container_name: "neutron_linuxbridge_agent" - container_privileged: "True" - container_volumes: +- name: Starting Neutron-linuxbridge-agent container + docker: + docker_api_version: "{{ docker_api_version }}" + net: host + pull: "{{ docker_pull_policy }}" + restart_policy: "{{ docker_restart_policy }}" + restart_policy_retry: "{{ docker_restart_policy_retry }}" + state: reloaded + registry: "{{ docker_registry }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + insecure_registry: "{{ docker_insecure_registry }}" + privileged: True + name: neutron_linuxbridge_agent + image: "{{ neutron_linuxbridge_agent_image_full }}" + volumes: - "/run:/run" - "/lib/modules:/lib/modules:ro" - "{{ node_config_directory }}/neutron-linuxbridge-agent/:/opt/kolla/neutron-linuxbridge-agent/:ro" + env: + KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" + NEUTRON_BRIDGE: "br-ex" + NEUTRON_INTERFACE: "{{ neutron_external_interface }}" when: (inventory_hostname in groups['compute'] or inventory_hostname in groups['neutron-agents']) and neutron_plugin_agent == "linuxbridge" -- include: ../../start.yml - vars: - container_environment: - KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - container_image: "{{ docker_neutron_agents_image_full }}" - container_name: "neutron_agents" - container_privileged: "True" - container_volumes: +- name: Starting Neutron-agents container + docker: + docker_api_version: "{{ docker_api_version }}" + net: host + pull: "{{ docker_pull_policy }}" + restart_policy: "{{ docker_restart_policy }}" + restart_policy_retry: "{{ docker_restart_policy_retry }}" + state: reloaded + registry: "{{ docker_registry }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + insecure_registry: "{{ docker_insecure_registry }}" + privileged: True + name: neutron_agents + image: "{{ neutron_agents_image_full }}" + volumes: - "/run:/run" - "{{ node_config_directory }}/neutron-agents/:/opt/kolla/neutron-agents/:ro" + env: + KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" when: inventory_hostname in groups['neutron-agents'] -