tenks/ansible/roles/virtualbmc-daemon/tasks/main.yml

107 lines
2.9 KiB
YAML

---
- name: Gather os specific variables
include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.distribution }}.yml"
- "{{ ansible_facts.os_family }}.yml"
skip: true
tags: vars
- name: Ensure package dependencies are installed
package:
name: "{{ vbmcd_packages }}"
state: present
register: result
until: result is success
retries: 3
become: true
# NOTE(priteau): We need a recent pip to install the latest cryptography
# library. See https://github.com/pyca/cryptography/issues/5753
- name: Ensure a recent version of pip is installed
pip:
name: "pip>=19.1.1"
virtualenv: "{{ vbmcd_virtualenv_path or omit }}"
become: "{{ not vbmcd_virtualenv_path }}"
- name: Create the temporary u-c file
tempfile:
state: file
suffix: u-c
register: u_c_file
- name: Download u-c
get_url:
url: "{{ vbmcd_python_upper_constraints_url }}"
dest: "{{ u_c_file.path }}"
mode: "0644"
register: result
until: result is success
retries: 3
# NOTE(yoctozepto): It is preferable to use the libvirt python binding that
# is delivered with the distribution as it is guaranteed to work with the
# deployed daemon (and the accompanying Python).
- name: Remove libvirt-python from u-c
lineinfile:
path: "{{ u_c_file.path }}"
state: absent
regexp: '^libvirt-python'
- name: Ensure Python requirements are installed
pip:
name: virtualbmc
extra_args: -c {{ u_c_file.path }}
virtualenv: "{{ vbmcd_virtualenv_path or omit }}"
register: result
until: result is success
retries: 3
become: "{{ not vbmcd_virtualenv_path }}"
- name: Remove the temporary u-c file
file:
path: "{{ u_c_file.path }}"
state: absent
- name: "[selinux] Allow systemd to start vbmcd from venv"
when:
- ansible_facts.selinux.status | default('disabled') == 'enabled'
- vbmcd_virtualenv_path
block:
- name: "[selinux] Allow systemd to start vbmcd from venv - sefcontext"
become: true
sefcontext:
target: "{{ vbmcd_virtualenv_path }}/bin(/.*)?"
setype: bin_t
state: present
register: sefcontext
- name: "[selinux] Allow systemd to start vbmcd from venv - restorecon" # noqa no-handler
become: true
command: "restorecon -r {{ vbmcd_virtualenv_path }}/bin"
when: sefcontext.changed
changed_when: true
- name: Ensure Virtual BMC systemd service is configured
template:
src: templates/{{ item }}.j2
dest: /etc/systemd/system/{{ item }}
owner: root
group: root
mode: "0644"
become: true
register: service_file
loop:
- "{{ service }}.service"
- name: Ensure Virtual BMC systemd service is started and enabled
systemd:
name: "{{ service }}"
enabled: true
state: started
daemon_reload: "{{ service_file.changed }}"
become: true