From 4acbf52867f9c0d15f56b6cf45bf9add62129c9f Mon Sep 17 00:00:00 2001 From: Mark Goddard <mark@stackhpc.com> Date: Fri, 15 Sep 2017 10:40:13 +0100 Subject: [PATCH] Untangle configuration of kolla and kolla-ansible Kolla (container images) and kolla-ansible (container deployment) are separate concerns, and should be treated as such. Configuration variables have been added for kolla-ansible which were previously shared between the two projects: kolla_venv -> kolla_ansible_venv kolla_ctl_install_type -> kolla_ansible_ctl_install_type Also, we introduce specific variables for the source code repository checkout paths, which were previously both based on source_checkout_path: kolla_source_path kolla_ansible_source_path These changes help us to cleanly separate the configuration of paths on the local (Ansible control) host, from those on the managed (target) hosts. This is important because the local paths may be specific to the environment in which the user is running kayobe, but the remote paths are relatively fixed and specific to the cluster. --- ansible/group_vars/all/kolla | 21 ++++++++++++--- ansible/roles/kolla-ansible/defaults/main.yml | 10 +++---- ansible/roles/kolla-ansible/tasks/config.yml | 2 +- ansible/roles/kolla-ansible/tasks/install.yml | 22 +++++++-------- ansible/roles/kolla-ansible/vars/main.yml | 2 +- ansible/roles/kolla/defaults/main.yml | 4 +-- ansible/roles/kolla/tasks/install.yml | 6 ++--- doc/source/configuration/kolla-ansible.rst | 27 +++++++++++++++++++ doc/source/index.rst | 1 + etc/kayobe/kolla.yml | 23 +++++++++++++++- kayobe/kolla_ansible.py | 19 +++++-------- kayobe/tests/unit/test_kolla_ansible.py | 13 ++++----- 12 files changed, 105 insertions(+), 45 deletions(-) create mode 100644 doc/source/configuration/kolla-ansible.rst diff --git a/ansible/group_vars/all/kolla b/ansible/group_vars/all/kolla index 0b89f629..1087ed51 100644 --- a/ansible/group_vars/all/kolla +++ b/ansible/group_vars/all/kolla @@ -5,6 +5,9 @@ # Type of Kolla control installation. One of 'binary' or 'source'. kolla_ctl_install_type: source +# Path to directory for kolla source code checkout. +kolla_source_path: "{{ source_checkout_path ~ '/kolla' }}" + # URL of Kolla source code repository if type is 'source'. kolla_source_url: "https://github.com/stackhpc/kolla" @@ -12,6 +15,18 @@ kolla_source_url: "https://github.com/stackhpc/kolla" # 'source'. kolla_source_version: "stackhpc-{{ kolla_openstack_release }}" +# Path to virtualenv in which to install kolla. +kolla_venv: "{{ virtualenv_path ~ '/kolla' }}" + +############################################################################### +# Kolla-ansible installation. + +# Type of Kolla-ansible control installation. One of 'binary' or 'source'. +kolla_ansible_ctl_install_type: source + +# Path to directory for kolla-ansible source code checkout. +kolla_ansible_source_path: "{{ lookup('env', 'KOLLA_SOURCE_PATH') | default(lookup('env', 'PWD') ~ '/src/kolla-ansible', true) }}" + # URL of Kolla Ansible source code repository if type is 'source'. kolla_ansible_source_url: "https://github.com/stackhpc/kolla-ansible" @@ -19,11 +34,11 @@ kolla_ansible_source_url: "https://github.com/stackhpc/kolla-ansible" # is 'source'. kolla_ansible_source_version: "stackhpc-{{ kolla_openstack_release }}" -# Path to virtualenv in which to install kolla. -kolla_venv: "{{ virtualenv_path ~ '/kolla' }}" +# Path to virtualenv in which to install kolla-ansible. +kolla_ansible_venv: "{{ lookup('env', 'KOLLA_VENV_PATH') | default(lookup('env', 'PWD') ~ '/venvs/kolla-ansible', true) }}" ############################################################################### -# Kolla configuration. +# Kolla & kolla-ansible configuration. # Path to Kolla configuration directory. kolla_config_path: "{{ lookup('env', 'KOLLA_CONFIG_PATH') | default('/etc/kolla', true) }}" diff --git a/ansible/roles/kolla-ansible/defaults/main.yml b/ansible/roles/kolla-ansible/defaults/main.yml index 0321ab6c..9be0d1ad 100644 --- a/ansible/roles/kolla-ansible/defaults/main.yml +++ b/ansible/roles/kolla-ansible/defaults/main.yml @@ -1,9 +1,9 @@ --- -# Path to directory for source code checkouts. -source_checkout_path: +# Path to directory for kolla-ansible source code checkout. +kolla_ansible_source_path: -# Type of Kolla control installation. One of 'binary' or 'source'. -kolla_ctl_install_type: +# Type of Kolla-ansible control installation. One of 'binary' or 'source'. +kolla_ansible_ctl_install_type: # URL of Kolla Ansible source code repository if type is 'source'. kolla_ansible_source_url: @@ -13,7 +13,7 @@ kolla_ansible_source_url: kolla_ansible_source_version: # Virtualenv directory where Kolla-ansible will be installed. -kolla_venv: "{{ ansible_env['PWD'] }}/kolla-venv" +kolla_ansible_venv: "{{ ansible_env['PWD'] }}/kolla-venv" # Password to use to encrypt the passwords.yml file. kolla_ansible_vault_password: diff --git a/ansible/roles/kolla-ansible/tasks/config.yml b/ansible/roles/kolla-ansible/tasks/config.yml index b7d80703..1a2686c9 100644 --- a/ansible/roles/kolla-ansible/tasks/config.yml +++ b/ansible/roles/kolla-ansible/tasks/config.yml @@ -41,7 +41,7 @@ sample: "{{ kolla_ansible_install_dir }}/etc_examples/kolla/passwords.yml" overrides: "{{ kolla_ansible_custom_passwords }}" vault_password: "{{ kolla_ansible_vault_password }}" - virtualenv: "{{ kolla_venv or omit }}" + virtualenv: "{{ kolla_ansible_venv or omit }}" - name: Ensure the Kolla passwords file is copied into place copy: diff --git a/ansible/roles/kolla-ansible/tasks/install.yml b/ansible/roles/kolla-ansible/tasks/install.yml index dd0ee5ac..172eb2d7 100644 --- a/ansible/roles/kolla-ansible/tasks/install.yml +++ b/ansible/roles/kolla-ansible/tasks/install.yml @@ -16,27 +16,27 @@ become: True with_items: "{{ kolla_ansible_package_dependencies }}" -- name: Ensure source code checkout path exists +- name: Ensure source code checkout parent directory exists file: - path: "{{ source_checkout_path }}" + path: "{{ kolla_ansible_source_path | dirname }}" state: directory owner: "{{ ansible_user }}" group: "{{ ansible_user }}" become: True - when: "{{ kolla_ctl_install_type == 'source' }}" + when: "{{ kolla_ansible_ctl_install_type == 'source' }}" - name: Ensure Kolla Ansible source code checkout exists git: repo: "{{ kolla_ansible_source_url }}" - dest: "{{ source_checkout_path }}/kolla-ansible" + dest: "{{ kolla_ansible_source_path }}" version: "{{ kolla_ansible_source_version }}" - when: "{{ kolla_ctl_install_type == 'source' }}" + when: "{{ kolla_ansible_ctl_install_type == 'source' }}" - name: Ensure the latest version of pip is installed pip: name: "{{ item.name }}" state: latest - virtualenv: "{{ kolla_venv }}" + virtualenv: "{{ kolla_ansible_venv }}" with_items: - { name: pip } @@ -45,15 +45,15 @@ name: "{{ item.name }}" version: "{{ item.version | default(omit) }}" state: present - virtualenv: "{{ kolla_venv }}" + virtualenv: "{{ kolla_ansible_venv }}" with_items: # Intall Kolla Ansible from source. - - name: "{{ source_checkout_path }}/kolla-ansible" - install: "{{ kolla_ctl_install_type == 'source' }}" + - name: "{{ kolla_ansible_source_path }}" + install: "{{ kolla_ansible_ctl_install_type == 'source' }}" # Intall Kolla Ansible from PyPI. - name: "kolla-ansible" version: "{{ kolla_openstack_release }}" - install: "{{ kolla_ctl_install_type == 'binary' }}" + install: "{{ kolla_ansible_ctl_install_type == 'binary' }}" # On CentOS 7.3 Jinja2==2.7, but kolla-ansible requires 2.8. Install # Ansible to ensure we pull in and use a later Jinja2. - name: "ansible" @@ -70,7 +70,7 @@ - name: Ensure selinux Python package is linked into the virtualenv file: src: "/usr/lib64/python2.7/site-packages/selinux" - dest: "{{ kolla_venv }}/lib/python2.7/site-packages/selinux" + dest: "{{ kolla_ansible_venv }}/lib/python2.7/site-packages/selinux" state: link when: - ansible_selinux != False diff --git a/ansible/roles/kolla-ansible/vars/main.yml b/ansible/roles/kolla-ansible/vars/main.yml index d6717225..143ede9f 100644 --- a/ansible/roles/kolla-ansible/vars/main.yml +++ b/ansible/roles/kolla-ansible/vars/main.yml @@ -6,7 +6,7 @@ kolla_ansible_is_standalone: "{{ kolla_ansible_source_version | version_compare( kolla_ansible_module: "{% if kolla_ansible_is_standalone | bool %}kolla-ansible{% else %}kolla{% endif %}" # Path to Kolla Ansible installation directory. -kolla_ansible_install_dir: "{{ kolla_venv }}/share/{{ kolla_ansible_module }}" +kolla_ansible_install_dir: "{{ kolla_ansible_venv }}/share/{{ kolla_ansible_module }}" ############################################################################### # Inventory configuration. diff --git a/ansible/roles/kolla/defaults/main.yml b/ansible/roles/kolla/defaults/main.yml index 34be6497..315bb30a 100644 --- a/ansible/roles/kolla/defaults/main.yml +++ b/ansible/roles/kolla/defaults/main.yml @@ -1,6 +1,6 @@ --- -# Path to directory for source code checkouts. -source_checkout_path: +# Path to directory for kolla source code checkout. +kolla_source_path: # Type of Kolla control installation. One of 'binary' or 'source'. kolla_ctl_install_type: diff --git a/ansible/roles/kolla/tasks/install.yml b/ansible/roles/kolla/tasks/install.yml index 291059cf..30314806 100644 --- a/ansible/roles/kolla/tasks/install.yml +++ b/ansible/roles/kolla/tasks/install.yml @@ -20,7 +20,7 @@ - name: Ensure source code checkout path exists file: - path: "{{ source_checkout_path }}" + path: "{{ kolla_source_path | dirname }}" state: directory owner: "{{ ansible_user }}" group: "{{ ansible_user }}" @@ -30,7 +30,7 @@ - name: Ensure Kolla source code checkout exists git: repo: "{{ kolla_source_url }}" - dest: "{{ source_checkout_path }}/kolla" + dest: "{{ kolla_source_path }}" version: "{{ kolla_source_version }}" when: "{{ kolla_ctl_install_type == 'source' }}" @@ -50,7 +50,7 @@ virtualenv: "{{ kolla_venv }}" with_items: # Intall Kolla from source. - - name: "{{ source_checkout_path }}/kolla" + - name: "{{ kolla_source_path }}" install: "{{ kolla_ctl_install_type == 'source' }}" # Intall Kolla from PyPI. - name: "kolla" diff --git a/doc/source/configuration/kolla-ansible.rst b/doc/source/configuration/kolla-ansible.rst new file mode 100644 index 00000000..2f3cf0c3 --- /dev/null +++ b/doc/source/configuration/kolla-ansible.rst @@ -0,0 +1,27 @@ +=========================== +Kolla-ansible Configuration +=========================== + +Kayobe relies heavily on kolla-ansible for deployment of the OpenStack control +plane. Kolla-ansible is installed locally on the ansible control host (the host +from which kayobe commands are executed), and kolla-ansible commands are +executed from there. + +Local Environment +================= + +Environment variables are used to configure the environment in which +kolla-ansible is installed and executed. + +.. table:: Kolla-ansible environment variables + + ====================== ================================================== ============================ + Variable Purpose Default + ====================== ================================================== ============================ + ``$KOLLA_CONFIG_PATH`` Path on the ansible control host in which ``/etc/kolla`` + the kolla-ansible configuration will be generated. + ``$KOLLA_SOURCE_PATH`` Path on the ansible control host in which ``$PWD/src/kolla-ansible`` + the kolla-ansible source code will be cloned. + ``$KOLLA_VENV_PATH`` Path on the ansible control host in which ``$PWD/venvs/kolla-ansible`` + the kolla-ansible virtualenv will be created. + ====================== ================================================== ============================ diff --git a/doc/source/index.rst b/doc/source/index.rst index a34cd9b2..210101b1 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -25,6 +25,7 @@ Documentation usage configuration/kayobe configuration/network + configuration/kolla-ansible deployment upgrading administration diff --git a/etc/kayobe/kolla.yml b/etc/kayobe/kolla.yml index 21be0750..78a4d7e7 100644 --- a/etc/kayobe/kolla.yml +++ b/etc/kayobe/kolla.yml @@ -7,6 +7,9 @@ # Type of Kolla control installation. One of 'binary' or 'source'. #kolla_ctl_install_type: +# Path to directory for kolla source code checkout. +#kolla_source_path: + # URL of Kolla source code repository if type is 'source'. #kolla_source_url: @@ -14,6 +17,18 @@ # 'source'. #kolla_source_version: +# Path to virtualenv in which to install kolla. +#kolla_venv: + +############################################################################### +# Kolla-ansible installation. + +# Type of Kolla-ansible control installation. One of 'binary' or 'source'. +#kolla_ansible_ctl_install_type: + +# Path to directory for kolla-ansible source code checkout. +#kolla_ansible_source_path: + # URL of Kolla Ansible source code repository if type is 'source'. #kolla_ansible_source_url: @@ -21,12 +36,18 @@ # is 'source'. #kolla_ansible_source_version: +# Path to virtualenv in which to install kolla-ansible. +#kolla_ansible_venv: + ############################################################################### -# Kolla configuration. +# Kolla & kolla-ansible configuration. # Path to Kolla configuration directory. #kolla_config_path: +# Path to Kolla node custom configuration directory. +#kolla_node_custom_config_path: + # Kolla base container image distribution. #kolla_base_distro: diff --git a/kayobe/kolla_ansible.py b/kayobe/kolla_ansible.py index 3819735a..49ca3269 100644 --- a/kayobe/kolla_ansible.py +++ b/kayobe/kolla_ansible.py @@ -25,24 +25,20 @@ DEFAULT_CONFIG_PATH = "/etc/kolla" CONFIG_PATH_ENV = "KOLLA_CONFIG_PATH" -DEFAULT_BASE_PATH = "/opt/kayobe" +DEFAULT_VENV_PATH = "venvs/kolla-ansible" -BASE_PATH_ENV = "KAYOBE_BASE_PATH" - -DEFAULT_VENV_PATH = "venvs/kolla" - -VENV_PATH_ENV = "KOLLA_VENV" +VENV_PATH_ENV = "KOLLA_VENV_PATH" LOG = logging.getLogger(__name__) def add_args(parser): """Add arguments required for running Kolla Ansible to a parser.""" + # $KOLLA_CONFIG_PATH or /etc/kolla. default_config_path = os.getenv(CONFIG_PATH_ENV, DEFAULT_CONFIG_PATH) + # $KOLLA_VENV_PATH or $PWD/venvs/kolla-ansible default_venv = os.getenv(VENV_PATH_ENV, - os.path.join(os.getenv(BASE_PATH_ENV, - DEFAULT_BASE_PATH), - DEFAULT_VENV_PATH)) + os.path.join(os.getcwd(), DEFAULT_VENV_PATH)) parser.add_argument("--kolla-config-path", default=default_config_path, help="path to Kolla configuration. " "(default=$%s or %s)" % @@ -64,9 +60,8 @@ def add_args(parser): "values in Kolla Ansible") parser.add_argument("--kolla-venv", metavar="VENV", default=default_venv, help="path to virtualenv where Kolla Ansible is " - "installed (default=$%s or $%s/%s, or %s/%s)" % - (VENV_PATH_ENV, BASE_PATH_ENV, DEFAULT_VENV_PATH, - DEFAULT_BASE_PATH, DEFAULT_VENV_PATH)) + "installed (default=$%s or $PWD/%s)" % + (VENV_PATH_ENV, DEFAULT_VENV_PATH)) def _get_inventory_path(parsed_args, inventory_filename): diff --git a/kayobe/tests/unit/test_kolla_ansible.py b/kayobe/tests/unit/test_kolla_ansible.py index 78de660b..d12b4670 100644 --- a/kayobe/tests/unit/test_kolla_ansible.py +++ b/kayobe/tests/unit/test_kolla_ansible.py @@ -24,6 +24,7 @@ from kayobe import utils from kayobe import vault +@mock.patch.object(os, "getcwd", new=lambda: "/path/to/cwd") class TestCase(unittest.TestCase): @mock.patch.object(utils, "run_command") @@ -35,7 +36,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args([]) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - ".", "/opt/kayobe/venvs/kolla/bin/activate", "&&", + ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&", "kolla-ansible", "command", "--inventory", "/etc/kolla/inventory/overcloud", ] @@ -58,7 +59,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args(args) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - ".", "/opt/kayobe/venvs/kolla/bin/activate", "&&", + ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&", "kolla-ansible", "command", "--inventory", "/path/to/inventory", "--configdir", "/path/to/config", @@ -87,7 +88,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args(args) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - ".", "/opt/kayobe/venvs/kolla/bin/activate", "&&", + ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&", "kolla-ansible", "command", "--inventory", "/path/to/inventory", "--configdir", "/path/to/config", @@ -111,7 +112,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args(args) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - ".", "/opt/kayobe/venvs/kolla/bin/activate", "&&", + ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&", "kolla-ansible", "command", "--key", "/path/to/vault/pw", "--inventory", "/etc/kolla/inventory/overcloud", @@ -134,7 +135,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args([]) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - ".", "/opt/kayobe/venvs/kolla/bin/activate", "&&", + ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&", "kolla-ansible", "command", "--key", "/path/to/kayobe-vault-password-helper", "--inventory", "/etc/kolla/inventory/overcloud", @@ -161,7 +162,7 @@ class TestCase(unittest.TestCase): } kolla_ansible.run(parsed_args, "command", "overcloud", **kwargs) expected_cmd = [ - ".", "/opt/kayobe/venvs/kolla/bin/activate", "&&", + ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&", "kolla-ansible", "command", "-v", "--inventory", "/etc/kolla/inventory/overcloud", -- GitLab