diff --git a/ansible-test-env.rc b/ansible-test-env.rc index b09d2f07c..4db655f97 100644 --- a/ansible-test-env.rc +++ b/ansible-test-env.rc @@ -1,9 +1,9 @@ export TRIPLEO_ANSIBLE_WORKPATH="$(dirname $(readlink -f ${BASH_SOURCE[0]}))" export ANSIBLE_STDOUT_CALLBACK=debug -export ANSIBLE_ACTION_PLUGINS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/action" +export ANSIBLE_ACTION_PLUGINS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/roles.galaxy/config_template/action:${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/action" export ANSIBLE_CALLBACK_PLUGINS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/callback" export ANSIBLE_FILTER_PLUGINS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/filter" -export ANSIBLE_LIBRARY="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/modules" +export ANSIBLE_LIBRARY="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/roles.galaxy/config_template/library:${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/modules" export ANSIBLE_MODULE_UTILS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/module_utils" export ANSIBLE_ROLES_PATH="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/roles.galaxy:${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/roles" export ANSIBLE_INVENTORY="${TRIPLEO_ANSIBLE_WORKPATH}/tests/hosts.ini" diff --git a/doc/source/roles/role-tripleo-config.rst b/doc/source/roles/role-tripleo-config.rst new file mode 100644 index 000000000..4684c18d2 --- /dev/null +++ b/doc/source/roles/role-tripleo-config.rst @@ -0,0 +1,6 @@ +===================== +Role - tripleo-config +===================== + +.. ansibleautoplugin:: + :role: tripleo_ansible/roles/tripleo-config diff --git a/tox.ini b/tox.ini index aa2c55a2c..940813d4e 100644 --- a/tox.ini +++ b/tox.ini @@ -9,10 +9,10 @@ install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/ passenv = * setenv = VIRTUAL_ENV={envdir} - ANSIBLE_ACTION_PLUGINS={toxinidir}/tripleo_ansible/ansible_plugins/action + ANSIBLE_ACTION_PLUGINS={toxinidir}/tripleo_ansible/roles.galaxy/config_template/action:{toxinidir}/tripleo_ansible/ansible_plugins/action ANSIBLE_CALLBACK_PLUGINS={toxinidir}/tripleo_ansible/ansible_plugins/callback ANSIBLE_FILTER_PLUGINS={toxinidir}/tripleo_ansible/ansible_plugins/filter - ANSIBLE_LIBRARY={toxinidir}/tripleo_ansible/ansible_plugins/modules + ANSIBLE_LIBRARY={toxinidir}/tripleo_ansible/roles.galaxy/config_template/library:{toxinidir}/tripleo_ansible/ansible_plugins/modules ANSIBLE_MODULE_UTILS={toxinidir}/tripleo_ansible/ansible_plugins/module_utils ANSIBLE_ROLES_PATH={toxinidir}/tripleo_ansible/roles.galaxy:{toxinidir}/tripleo_ansible/roles ANSIBLE_INVENTORY={toxinidir}/tests/hosts.ini diff --git a/tripleo_ansible/ansible-role-requirements.yml b/tripleo_ansible/ansible-role-requirements.yml index e5de7ea8a..e08242515 100644 --- a/tripleo_ansible/ansible-role-requirements.yml +++ b/tripleo_ansible/ansible-role-requirements.yml @@ -16,6 +16,13 @@ - name: openstack-operations scm: git - src: https://github.com/openstack/ansible-role-openstack-operations + src: https://opendev.org/openstack/ansible-role-openstack-operations + version: master + trackbranch: master + +# ansible-config_template action plugin +- name: config_template + scm: git + src: https://opendev.org/openstack/ansible-config_template version: master trackbranch: master diff --git a/tripleo_ansible/roles/tripleo-config/defaults/main.yml b/tripleo_ansible/roles/tripleo-config/defaults/main.yml new file mode 100644 index 000000000..a2bb606c5 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-config/defaults/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. + + +# All variables intended for modification should place placed in this file. + +# All variables within this role should have a prefix of "tripleo-config" +tripleo_config_type: ini +tripleo_config_owner: root +tripleo_config_group: root +tripleo_config_mode: 0644 +tripleo_config_overrides: {} diff --git a/tripleo_ansible/roles/tripleo-config/meta/main.yml b/tripleo_ansible/roles/tripleo-config/meta/main.yml new file mode 100644 index 000000000..b8898ccf8 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-config/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-config + 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-config/molecule/default/Dockerfile b/tripleo_ansible/roles/tripleo-config/molecule/default/Dockerfile new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/tripleo_ansible/roles/tripleo-config/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-config/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo-config/molecule/default/molecule.yml new file mode 100644 index 000000000..3a32890d4 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-config/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-config/molecule/default/playbook.yml b/tripleo_ansible/roles/tripleo-config/molecule/default/playbook.yml new file mode 100644 index 000000000..77d754f52 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-config/molecule/default/playbook.yml @@ -0,0 +1,28 @@ +--- +# 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 + roles: + - role: "tripleo-config" + tripleo_config_dest: /tmp/test.ini + + - role: "tripleo-config" + tripleo_config_dest: /tmp/test2.ini + tripleo_config_overrides: + testSection: + test_option: var1 diff --git a/tripleo_ansible/roles/tripleo-config/molecule/default/prepare.yml b/tripleo_ansible/roles/tripleo-config/molecule/default/prepare.yml new file mode 100644 index 000000000..ef85c3128 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-config/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-config/tasks/main.yml b/tripleo_ansible/roles/tripleo-config/tasks/main.yml new file mode 100644 index 000000000..e432077ff --- /dev/null +++ b/tripleo_ansible/roles/tripleo-config/tasks/main.yml @@ -0,0 +1,32 @@ +--- +# 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: Check for a configured destination + fail: + msg: >- + The option `tripleo_config_dest` is undefined. Check your settings. + when: + - tripleo_config_dest is undefined + +- name: "Generate {{ tripleo_config_dest }} config" + config_template: + src: "{{ tripleo_config_type }}-config.j2" + dest: "{{ tripleo_config_dest }}" + owner: "{{ tripleo_config_owner }}" + group: "{{ tripleo_config_group }}" + mode: "{{ tripleo_config_mode }}" + config_overrides: "{{ tripleo_config_overrides }}" + config_type: "{{ tripleo_config_type }}" diff --git a/tripleo_ansible/roles/tripleo-config/templates/ini-config.j2 b/tripleo_ansible/roles/tripleo-config/templates/ini-config.j2 new file mode 100644 index 000000000..e2bb15330 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-config/templates/ini-config.j2 @@ -0,0 +1 @@ +# {{ ansible_managed }} diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 2008b56f0..6d93f5e21 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -21,6 +21,7 @@ - tripleo-ansible-centos-7-molecule-tripleo-ceph-run-ansible - tripleo-ansible-centos-7-molecule-login-defs - tripleo-ansible-centos-7-molecule-tripleo-time + - tripleo-ansible-centos-7-molecule-tripleo-config gate: jobs: - tripleo-ansible-centos-7-molecule-aide @@ -42,6 +43,7 @@ - tripleo-ansible-centos-7-molecule-tripleo-ceph-run-ansible - tripleo-ansible-centos-7-molecule-login-defs - tripleo-ansible-centos-7-molecule-tripleo-time + - tripleo-ansible-centos-7-molecule-tripleo-config name: tripleo-ansible-molecule-jobs - job: files: @@ -182,3 +184,10 @@ parent: tripleo-ansible-centos-7-base vars: tripleo_role_name: tripleo-time +- job: + files: + - ^tripleo_ansible/roles/tripleo-config/.* + name: tripleo-ansible-centos-7-molecule-tripleo-config + parent: tripleo-ansible-centos-7-base + vars: + tripleo_role_name: tripleo-config diff --git a/zuul.d/playbooks/pre.yml b/zuul.d/playbooks/pre.yml index 27874d985..3e980f845 100644 --- a/zuul.d/playbooks/pre.yml +++ b/zuul.d/playbooks/pre.yml @@ -2,6 +2,18 @@ - hosts: all pre_tasks: + - name: Set project path fact + set_fact: + tripleo_ansible_project_path: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}" + + - name: Set action plugin path fact + set_fact: + tripleo_action_plugins_paths: + - "{{ tripleo_ansible_project_path }}/tripleo_ansible/roles.galaxy/config_template/action" + - "{{ tripleo_ansible_project_path }}/tripleo_ansible/ansible_plugins/action" + - "/usr/share/ansible/plugins/action" + - "/usr/share/ansible/tripleo-plugins/action" + - name: Ensure output dirs file: path: "{{ ansible_user_dir }}/zuul-output/logs" @@ -16,13 +28,21 @@ - name: Run bindep shell: |- . {{ ansible_user_dir }}/test-python/bin/activate - {{ ansible_user_dir }}/{{ zuul.project.src_dir }}/scripts/bindep-install + {{ tripleo_ansible_project_path }}/scripts/bindep-install become: true - name: Setup test-python pip: - requirements: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/molecule-requirements.txt" + requirements: "{{ tripleo_ansible_project_path }}/molecule-requirements.txt" virtualenv: "{{ ansible_user_dir }}/test-python" virtualenv_site_packages: true + tasks: + - name: Get Ansible Galaxy roles + command: >- + {{ ansible_user_dir }}/test-python/bin/ansible-galaxy install + -fr + {{ tripleo_ansible_project_path }}/tripleo_ansible/ansible-role-requirements.yml + environment: + ANSIBLE_ROLES_PATH: "{{ tripleo_ansible_project_path }}/tripleo_ansible/roles.galaxy" roles: - role: install-docker diff --git a/zuul.d/playbooks/run.yml b/zuul.d/playbooks/run.yml index 02232bc64..7ef78bd64 100644 --- a/zuul.d/playbooks/run.yml +++ b/zuul.d/playbooks/run.yml @@ -3,17 +3,31 @@ - hosts: all environment: ANSIBLE_LOG_PATH: "{{ ansible_user_dir }}/zuul-output/logs/ansible-execution.log" + pre_tasks: + - name: Set project path fact + set_fact: + tripleo_ansible_project_path: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}" + + - name: Set action plugin path fact + set_fact: + tripleo_action_plugins_paths: + - "{{ tripleo_ansible_project_path }}/tripleo_ansible/roles.galaxy/config_template/action" + - "{{ tripleo_ansible_project_path }}/tripleo_ansible/ansible_plugins/action" + - "/usr/share/ansible/plugins/action" + - "/usr/share/ansible/tripleo-plugins/action" tasks: - name: Run role test job shell: |- . {{ ansible_user_dir }}/test-python/bin/activate - . {{ ansible_user_dir }}/{{ zuul.project.src_dir }}/ansible-test-env.rc + . {{ tripleo_ansible_project_path }}/ansible-test-env.rc pytest --color=no \ --html={{ ansible_user_dir }}/zuul-output/logs/reports.html \ --self-contained-html \ -s \ --ansible-args='{{ tripleo_job_ansible_args | default("-v") }}' \ - {{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/test_molecule.py + {{ tripleo_ansible_project_path }}/tests/test_molecule.py args: - chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tripleo_ansible/roles/{{ tripleo_role_name }}" + chdir: "{{ tripleo_ansible_project_path }}/tripleo_ansible/roles/{{ tripleo_role_name }}" executable: /bin/bash + environment: + ANSIBLE_ACTION_PLUGINS: "{{ tripleo_action_plugins_paths | join(':') }}"