From 64d28e6f5f11e102c421f7e03d6bb44de3ffa7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Jeanneret?= Date: Tue, 20 Aug 2019 13:37:15 +0200 Subject: [PATCH] Adds tripleo-clients-install role This role allows to easily install either all or some of the openstack clients. Change-Id: I6fe8f2469207d75e2c7aa6621f6683a1949ac0ca Story: 2005984 Task: 34433 Task: 34434 Task: 34435 Task: 34436 --- .../roles/role-tripleo-clients-install.rst | 6 +++ .../roles/tripleo-clients-install/README.md | 30 ++++++++++++ .../tripleo-clients-install/defaults/main.yml | 41 ++++++++++++++++ .../tripleo-clients-install/meta/main.yml | 44 +++++++++++++++++ .../molecule/default/Dockerfile | 37 ++++++++++++++ .../molecule/default/molecule.yml | 48 +++++++++++++++++++ .../molecule/default/playbook.yml | 25 ++++++++++ .../molecule/default/prepare.yml | 21 ++++++++ .../tasks/install_pkgs.yml | 38 +++++++++++++++ .../tripleo-clients-install/tasks/main.yml | 25 ++++++++++ .../tripleo-clients-install/vars/fedora.yml | 24 ++++++++++ .../tripleo-clients-install/vars/main.yml | 24 ++++++++++ .../tripleo-clients-install/vars/redhat-8.yml | 24 ++++++++++ zuul.d/molecule.yaml | 11 ++++- 14 files changed, 397 insertions(+), 1 deletion(-) create mode 100644 doc/source/roles/role-tripleo-clients-install.rst create mode 100644 tripleo_ansible/roles/tripleo-clients-install/README.md create mode 100644 tripleo_ansible/roles/tripleo-clients-install/defaults/main.yml create mode 100644 tripleo_ansible/roles/tripleo-clients-install/meta/main.yml create mode 100644 tripleo_ansible/roles/tripleo-clients-install/molecule/default/Dockerfile create mode 100644 tripleo_ansible/roles/tripleo-clients-install/molecule/default/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo-clients-install/molecule/default/playbook.yml create mode 100644 tripleo_ansible/roles/tripleo-clients-install/molecule/default/prepare.yml create mode 100644 tripleo_ansible/roles/tripleo-clients-install/tasks/install_pkgs.yml create mode 100644 tripleo_ansible/roles/tripleo-clients-install/tasks/main.yml create mode 100644 tripleo_ansible/roles/tripleo-clients-install/vars/fedora.yml create mode 100644 tripleo_ansible/roles/tripleo-clients-install/vars/main.yml create mode 100644 tripleo_ansible/roles/tripleo-clients-install/vars/redhat-8.yml diff --git a/doc/source/roles/role-tripleo-clients-install.rst b/doc/source/roles/role-tripleo-clients-install.rst new file mode 100644 index 000000000..8d2435552 --- /dev/null +++ b/doc/source/roles/role-tripleo-clients-install.rst @@ -0,0 +1,6 @@ +============================== +Role - tripleo-clients-install +============================== + +.. ansibleautoplugin:: + :role: tripleo_ansible/roles/tripleo-clients-install diff --git a/tripleo_ansible/roles/tripleo-clients-install/README.md b/tripleo_ansible/roles/tripleo-clients-install/README.md new file mode 100644 index 000000000..d96bef957 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/README.md @@ -0,0 +1,30 @@ +# tripleo-clients-install + +Installs openstack clients packages + + +## Role Variables +### Common variables +- tripleo_clients_install_python_prefix: package prefix +```YAML +tripleo_clients_install_python_prefix: python3 +``` + +### main task +- tripleo_clients_install_dict: hash listing the different client and package + state: +```YAML +tripleo_clients_install_dict: + aodh: present + barbican: absent +``` + +### install_pkgs task +- tripleo_clients_install_client: client name you want to manage +```YAML +tripleo_clients_install_client: aodh +``` +- tripleo_clients_install_pkg_state: package state you want +```YAML +tripleo_clients_install_pkg_state: present +``` diff --git a/tripleo_ansible/roles/tripleo-clients-install/defaults/main.yml b/tripleo_ansible/roles/tripleo-clients-install/defaults/main.yml new file mode 100644 index 000000000..4604a4997 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/defaults/main.yml @@ -0,0 +1,41 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +# All variables intended for modification should place placed in this file. + +# All variables within this role should have a prefix of "tripleo_clients_install" +tripleo_clients_install_pkg_state: present + +tripleo_clients_install_dict: + aodh: present + barbican: present + cinder: present + designate: present + glance: present + gnocchi: present + heat: present + ironic: present + keystone: present + manila: present + mistral: present + neutron: present + nova: present + openstack: present + panko: present + sahara: present + swift: present + zaqar: present diff --git a/tripleo_ansible/roles/tripleo-clients-install/meta/main.yml b/tripleo_ansible/roles/tripleo-clients-install/meta/main.yml new file mode 100644 index 000000000..5369e628d --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/meta/main.yml @@ -0,0 +1,44 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +galaxy_info: + author: OpenStack + description: TripleO OpenStack Role -- tripleo-clients-install + company: Red Hat + license: Apache-2.0 + min_ansible_version: 2.7 + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: Fedora + versions: + - 28 + - name: CentOS + versions: + - 7 + + galaxy_tags: + - tripleo + + +# List your role dependencies here, one per line. Be sure to remove the '[]' above, +# if you add dependencies to this list. +dependencies: [] diff --git a/tripleo_ansible/roles/tripleo-clients-install/molecule/default/Dockerfile b/tripleo_ansible/roles/tripleo-clients-install/molecule/default/Dockerfile new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/molecule/default/Dockerfile @@ -0,0 +1,37 @@ +# Molecule managed +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi + +{% for pkg in item.easy_install | default([]) %} +# install pip for centos where there is no python-pip rpm in default repos +RUN easy_install {{ pkg }} +{% endfor %} + + +CMD ["sh", "-c", "while true; do sleep 10000; done"] diff --git a/tripleo_ansible/roles/tripleo-clients-install/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo-clients-install/molecule/default/molecule.yml new file mode 100644 index 000000000..3a32890d4 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/molecule/default/molecule.yml @@ -0,0 +1,48 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos7 + hostname: centos7 + image: centos:7 + dockerfile: Dockerfile + pkg_extras: python-setuptools + easy_install: + - pip + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + + - name: fedora28 + hostname: fedora28 + image: fedora:28 + dockerfile: Dockerfile + pkg_extras: python*-setuptools + environment: + <<: *env + +provisioner: + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +lint: + enabled: false + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/tripleo_ansible/roles/tripleo-clients-install/molecule/default/playbook.yml b/tripleo_ansible/roles/tripleo-clients-install/molecule/default/playbook.yml new file mode 100644 index 000000000..7654a19b7 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/molecule/default/playbook.yml @@ -0,0 +1,25 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +- name: Converge + hosts: all + vars: + tripleo_clients_install_dict: + aodh: installed + barbican: installed + roles: + - role: "tripleo-clients-install" diff --git a/tripleo_ansible/roles/tripleo-clients-install/molecule/default/prepare.yml b/tripleo_ansible/roles/tripleo-clients-install/molecule/default/prepare.yml new file mode 100644 index 000000000..ef85c3128 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/molecule/default/prepare.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +- name: Prepare + hosts: all + roles: + - role: test_deps diff --git a/tripleo_ansible/roles/tripleo-clients-install/tasks/install_pkgs.yml b/tripleo_ansible/roles/tripleo-clients-install/tasks/install_pkgs.yml new file mode 100644 index 000000000..37de7fe81 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/tasks/install_pkgs.yml @@ -0,0 +1,38 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +# "tripleo-clients-install" will search for and load any operating system variable file + +# found within the "vars/" path. If no OS files are found the task will skip. +- name: Gather variables for each operating system + include_vars: "{{ item }}" + with_first_found: + - skip: true + files: + - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml" + - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml" + - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml" + - "{{ ansible_distribution | lower }}.yml" + - "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml" + - "{{ ansible_os_family | lower }}.yml" + tags: + - always + +- name: "Ensure {{ tripleo_clients_install_client }} package state is {{ tripleo_clients_install_pkg_state }}" + package: + name: "{{ tripleo_clients_install_python_prefix }}-{{ tripleo_clients_install_client }}client" + state: "{{ tripleo_clients_install_pkg_state }}" diff --git a/tripleo_ansible/roles/tripleo-clients-install/tasks/main.yml b/tripleo_ansible/roles/tripleo-clients-install/tasks/main.yml new file mode 100644 index 000000000..8c1570415 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/tasks/main.yml @@ -0,0 +1,25 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Install all clients + include_tasks: install_pkgs.yml + vars: + tripleo_clients_install_client: "{{ pkg.key }}" + tripleo_clients_install_pkg_state: "{{ pkg.value }}" + loop: "{{ tripleo_clients_install_dict|dict2items }}" + loop_control: + loop_var: 'pkg' + label: "{{ pkg.key }}" diff --git a/tripleo_ansible/roles/tripleo-clients-install/vars/fedora.yml b/tripleo_ansible/roles/tripleo-clients-install/vars/fedora.yml new file mode 100644 index 000000000..af19af25e --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/vars/fedora.yml @@ -0,0 +1,24 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +# While options found within the vars/ path can be overridden using extra +# vars, items within this path are considered part of the role and not +# intended to be modified. + +# All variables within this role should have a prefix of "tripleo_clients_install_" + +tripleo_clients_install_python_prefix: python3 diff --git a/tripleo_ansible/roles/tripleo-clients-install/vars/main.yml b/tripleo_ansible/roles/tripleo-clients-install/vars/main.yml new file mode 100644 index 000000000..ef9a0071a --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/vars/main.yml @@ -0,0 +1,24 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +# While options found within the vars/ path can be overridden using extra +# vars, items within this path are considered part of the role and not +# intended to be modified. + +# All variables within this role should have a prefix of "tripleo_clients_install_" + +tripleo_clients_install_python_prefix: python diff --git a/tripleo_ansible/roles/tripleo-clients-install/vars/redhat-8.yml b/tripleo_ansible/roles/tripleo-clients-install/vars/redhat-8.yml new file mode 100644 index 000000000..af19af25e --- /dev/null +++ b/tripleo_ansible/roles/tripleo-clients-install/vars/redhat-8.yml @@ -0,0 +1,24 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +# While options found within the vars/ path can be overridden using extra +# vars, items within this path are considered part of the role and not +# intended to be modified. + +# All variables within this role should have a prefix of "tripleo_clients_install_" + +tripleo_clients_install_python_prefix: python3 diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index e6eda74af..40dd419fb 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -31,6 +31,7 @@ - tripleo-ansible-centos-7-molecule-tripleo-firewall - tripleo-ansible-centos-7-molecule-tripleo-securetty - tripleo-ansible-centos-7-molecule-tripleo-cellv2 + - tripleo-ansible-centos-7-molecule-tripleo-clients-install gate: jobs: - tripleo-ansible-centos-7-molecule-aide @@ -62,6 +63,7 @@ - tripleo-ansible-centos-7-molecule-tripleo-firewall - tripleo-ansible-centos-7-molecule-tripleo-securetty - tripleo-ansible-centos-7-molecule-tripleo-cellv2 + - tripleo-ansible-centos-7-molecule-tripleo-clients-install name: tripleo-ansible-molecule-jobs - job: files: @@ -251,7 +253,7 @@ parent: tripleo-ansible-centos-7-base vars: tripleo_docker_enable_vfs: true - tripleo_docker_temp_file: "{{ zuul.executor.work_root }}/.tmp/docker-daemon-{{ inventory_hostname }}.json" + tripleo_docker_temp_file: '{{ zuul.executor.work_root }}/.tmp/docker-daemon-{{ inventory_hostname }}.json' tripleo_role_name: tripleo-container-image-prepare - job: files: @@ -274,3 +276,10 @@ parent: tripleo-ansible-centos-7-base vars: tripleo_role_name: tripleo-cellv2 +- job: + files: + - ^tripleo_ansible/roles/tripleo-clients-install/.* + name: tripleo-ansible-centos-7-molecule-tripleo-clients-install + parent: tripleo-ansible-centos-7-base + vars: + tripleo_role_name: tripleo-clients-install