ara/roles/ara_api/tasks/pre-requirements.yaml
David Moreau Simard f8e31af454
role: Do not escalate privileges for creating base directories
Otherwise we can end up doing something like escalating privileges for
creating directories in /tmp/ and then the regular user won't have
access to them.

We can revisit this later if need be.

Change-Id: Ieb33c23f2d278ed1156a8bc2d39c41bb9b4bb6f6
2019-05-15 07:51:31 -04:00

73 lines
2.5 KiB
YAML

---
# Copyright (c) 2019 Red Hat, Inc.
#
# This file is part of ARA Records Ansible.
#
# ARA Records Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ARA Records Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ARA Records Ansible. If not, see <http://www.gnu.org/licenses/>.
# The ansible_python_version fact might end up retrieving the version of
# python2 so we need to explicitely get the version of python 3 available.
- name: Validate availability of Python 3.6
command: /usr/bin/python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))'
changed_when: false
failed_when: false
register: python_version
- name: Fail pre-emptively if running Python <3.6
fail:
msg: "Python >=3.6 is required to run ARA"
when: python_version.stdout is version('3.6', '<') or python_version.rc != 0
- name: Get list of installed packages
package_facts:
manager: "auto"
no_log: yes
- name: Retrieve list of missing required packages
set_fact:
ara_api_missing_packages: "{{ ara_api_required_packages | difference(ansible_facts.packages.keys()) }}"
# Only attempt to elevate privileges if there are any missing packages
- when: ara_api_missing_packages | length > 0
block:
- name: Install required packages
become: yes
package:
name: "{{ ara_api_required_packages }}"
state: present
rescue:
- name: Fail due to missing packages
fail:
msg: "Failed to elevate privileges and install missing required packages. Install the following packages before running this role again: {{ ara_missing_packages | join(' ') }}"
# The following tasks dynamically enable escalated privileges only when the
# directory to create is not located in the user's home directory.
- name: Ensure ara_api_root_dir exists
file:
path: "{{ ara_api_root_dir }}"
state: directory
mode: 0755
- name: Ensure ara_api_base_dir exists
file:
path: "{{ ara_api_base_dir }}"
state: directory
mode: 0750
- name: Ensure ara_api_log_dir exists
file:
path: "{{ ara_api_log_dir }}"
state: directory
mode: 0750