diff --git a/playbooks/roles/install-ansible/README.rst b/playbooks/roles/install-ansible/README.rst index 2654f74be3..304e87a0fb 100644 --- a/playbooks/roles/install-ansible/README.rst +++ b/playbooks/roles/install-ansible/README.rst @@ -37,3 +37,35 @@ Install and configure Ansible on a host via pip :zuul:rolevar:`install-ansible.install_ansible_openstacksdk_name`. The special value "latest" will ensure ``state: latest`` is set for the package and thus the latest version is always installed. + +.. zuul:rolevar:: install_ansible_ara_enable + :default: false + + Whether or not to install the ARA Records Ansible callback plugin + +.. zuul:rolevar:: install_ansible_ara_name + :default: ara + + The name of the ARA package to install. To install from + alternative sources, this can be a URL for a remote package. + +.. zuul:rolevar:: install_ansible_ara_version + :default: latest + + Version of ARA to install. Set this to empty (YAML ``null``) if + specifying versions via URL in + :zuul:rolevar:`install-ansible.install_ansible_ara_name`. The + special value "latest" will ensure ``state: latest`` is set for the + package and hence the latest version is always installed. + +.. zuul:rolevar:: install_ansible_ara_config + :default: {"database": "sqlite:////var/cache/ansible/ara.sqlite"} + + A dictionary of key-value pairs to be added to the ARA + configuration file + + *database*: Connection string for the database (ex: mysql+pymysql://ara:password@localhost/ara) + + For a list of available configuration options, see the `ARA documentation`_ + +.. _ARA documentation: https://ara.readthedocs.io/en/stable/configuration.html diff --git a/playbooks/roles/install-ansible/defaults/main.yaml b/playbooks/roles/install-ansible/defaults/main.yaml new file mode 100644 index 0000000000..8f0d0d3528 --- /dev/null +++ b/playbooks/roles/install-ansible/defaults/main.yaml @@ -0,0 +1,12 @@ +# Whether or not to install ARA +install_ansible_ara_enable: false + +# See available configuration options in the ARA docs: +# https://ara.readthedocs.io/en/stable/configuration.html +# Note that this may be set in the private host vars when using mysql so we can +# keep the credentials secret. +install_ansible_ara_config: + # Connection string for ARA + # https://ara.readthedocs.io/en/stable/configuration.html#ara-database + # Ex: mysql+pymysql://ara:password@localhost/ara + database: "sqlite:////var/cache/ansible/ara.sqlite" diff --git a/playbooks/roles/install-ansible/tasks/install_ara.yaml b/playbooks/roles/install-ansible/tasks/install_ara.yaml new file mode 100644 index 0000000000..08bc34ee17 --- /dev/null +++ b/playbooks/roles/install-ansible/tasks/install_ara.yaml @@ -0,0 +1,38 @@ +- name: Install pymysql for ara + pip: + name: pymysql + state: present + when: '"pymysql" in install_ansible_ara_config["database"]' + +# If ansible_install_ansible_ara_version is not defined it should be "latest" +- name: Set ara default version to latest + set_fact: + install_ansible_ara_version: latest + when: install_ansible_ara_version is not defined + +# If a version is not explicitly set we want to make sure to +# completely omit the version argument to pip, as it will be coming +# from the long-form install_ansible_ara_name variable. Additionally, +# if the version is the special value "latest", then we also want to +# omit any version number, but also set the package state to "latest". +- name: Set ARA version for installation + set_fact: + _install_ansible_ara_version: '{{ install_ansible_ara_version }}' + when: install_ansible_ara_version not in ('', 'latest') + +- name: Set ARA package state for installation + set_fact: + _install_ansible_ara_state: latest + when: install_ansible_ara_version == 'latest' + +- name: Install ARA + pip: + name: '{{ install_ansible_ara_name | default("ara") }}' + version: '{{ _install_ansible_ara_version | default(omit) }}' + state: '{{ _install_ansible_ara_state | default(omit) }}' + +# For configuring the callback plugins location in ansible.cfg +- name: Get ARA's location for callback plugins + command: python3 -m ara.setup.callback_plugins + register: install_ansible_ara_callback_plugins + changed_when: false diff --git a/playbooks/roles/install-ansible/tasks/main.yaml b/playbooks/roles/install-ansible/tasks/main.yaml index cd56a8e80b..983bdb2013 100644 --- a/playbooks/roles/install-ansible/tasks/main.yaml +++ b/playbooks/roles/install-ansible/tasks/main.yaml @@ -74,9 +74,13 @@ group: root mode: 0775 +- name: Set up the ARA callback + include_tasks: install_ara.yaml + when: install_ansible_ara_enable + - name: Copy ansible.cfg in to place - copy: - src: ansible.cfg + template: + src: ansible.cfg.j2 dest: /etc/ansible/ansible.cfg # NOTE(mordred) The copy of the openstack inventory plugin from 2.6 is busted. diff --git a/playbooks/roles/install-ansible/files/ansible.cfg b/playbooks/roles/install-ansible/templates/ansible.cfg.j2 similarity index 73% rename from playbooks/roles/install-ansible/files/ansible.cfg rename to playbooks/roles/install-ansible/templates/ansible.cfg.j2 index 3032de298b..0dd890f613 100644 --- a/playbooks/roles/install-ansible/files/ansible.cfg +++ b/playbooks/roles/install-ansible/templates/ansible.cfg.j2 @@ -2,8 +2,6 @@ inventory=/opt/system-config/inventory/openstack.yaml,/opt/system-config/inventory/groups.yaml,/etc/ansible/hosts/emergency.yaml library=/usr/share/ansible log_path=/var/log/ansible/ansible.log -callback_plugins=/etc/ansible/callback_plugins -callback_whitelist=profile_tasks, timer inventory_plugins=/etc/ansible/inventory_plugins roles_path=/opt/system-config/roles:/etc/ansible/roles retry_files_enabled=False @@ -11,6 +9,12 @@ retry_files_save_path= gathering=smart fact_caching=jsonfile fact_caching_connection=/var/cache/ansible/facts +callback_whitelist=profile_tasks, timer +{% if install_ansible_ara_enable %} +callback_plugins=/etc/ansible/callback_plugins:{{ install_ansible_ara_callback_plugins.stdout }} +{% else %} +callback_plugins=/etc/ansible/callback_plugins +{% endif %} [inventory] enable_plugins=yaml,yamlgroup,advanced_host_list,ini @@ -25,3 +29,10 @@ pipelining = True [callback_profile_tasks] task_output_limit = 50 + +{% if install_ansible_ara_enable %} +[ara] +{% for k, v in install_ansible_ara_config.items() %} +{{ k }}={{ v }} +{% endfor %} +{% endif %}