risotto/ansible/host.yml

144 lines
4.4 KiB
YAML
Raw Normal View History

2022-10-01 22:33:11 +02:00
---
- name: "Populate service facts"
service_facts:
- name: "Stop services"
when: item.value['manage'] and item.value['activate'] and item.value['doc'].endswith('.service') and not item.value['doc'].endswith('@.service') and item.value['engine'] != 'none'
ansible.builtin.service:
name: "{{ item.value['doc'] }}"
state: stopped
loop: "{{ vars[inventory_hostname]['services'] | dict2items }}"
loop_control:
label: "{{ item.value['doc'] }}"
- name: "Packages installation"
apt:
pkg: "{{ vars[inventory_hostname]['general']['host_packages'] }}"
update_cache: yes
state: latest
- name: "Build host files"
local_action:
module: rougail
hostname: "{{ inventory_hostname }}"
is_host: True
- name: "Create host directories"
file: path={{ item }} state=directory mode=0755
loop: "{{ vars[inventory_hostname]['services'] | directorieslist }}"
- name: "Copy systemd-tmpfiles"
when: item.name.startswith('/usr/local/lib/risotto-tmpfiles.d')
ansible.builtin.copy:
src: installations/{{ item.name }}
dest: "{{ item.name }}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
loop: "{{ vars[inventory_hostname]['services'] | fileslist(is_host=True) }}"
loop_control:
label: "{{ item.name}}"
- name: "Execute systemd-tmpfiles"
when: item.name.startswith('/usr/local/lib/risotto-tmpfiles.d')
command: /usr/bin/systemd-tmpfiles --create --clean --remove {{ item.name }}
loop: "{{ vars[inventory_hostname]['services'] | fileslist(is_host=True) }}"
loop_control:
label: "{{ item.name}}"
- name: "Copy host files"
when: not item.name.startswith('/usr/local/lib/tmpfiles.d')
ansible.builtin.copy:
src: installations/{{ item.name }}
dest: "{{ item.name }}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
loop: "{{ vars[inventory_hostname]['services'] | fileslist(is_host=True) }}"
loop_control:
label: "{{ item.name}}"
- name: "Reload systemd services configuration"
ansible.builtin.systemd:
daemon_reload: yes
- name: "Enable services"
when: item.value['manage'] and item.value['activate'] and '@.service' not in item.value['doc']
ansible.builtin.service:
name: "{{ item.value['doc'] }}"
enabled: yes
loop: "{{ vars[inventory_hostname]['services'] | dict2items }}"
loop_control:
label: "{{ item.value['doc'] }}"
- name: "Disable services"
when: item.value['manage'] and not item.value['activate'] and not item.value['undisable'] and '@.service' not in item.value['doc']
ansible.builtin.service:
name: "{{ item.value['doc'] }}"
enabled: yes
loop: "{{ vars[inventory_hostname]['services'] | dict2items }}"
loop_control:
label: "{{ item.value['doc'] }}"
- name: "Start services"
when: item.value['manage'] and item.value['activate'] and item.value['doc'].endswith('.service') and not item.value['doc'].endswith('@.service') and item.value['engine'] != 'none'
ansible.builtin.service:
name: "{{ item.value['doc'] }}"
state: started
loop: "{{ vars[inventory_hostname]['services'] | dict2items }}"
loop_control:
label: "{{ item.value['doc'] }}"
- name: "Restart services"
when: item.value['manage'] and item.value['activate'] and item.value['doc'].endswith('.service') and not item.value['doc'].endswith('@.service') and item.value['engine'] == 'none'
ansible.builtin.service:
name: "{{ item.value['doc'] }}"
state: restarted
loop: "{{ vars[inventory_hostname]['services'] | dict2items }}"
loop_control:
label: "{{ item.value['doc'] }}"
- name: "Copy machines scripts"
ansible.builtin.copy:
src: "{{ item }}"
dest: "/usr/local/sbin"
owner: "root"
group: "root"
mode: "0755"
loop: "{{ lookup('fileglob', '../sbin/*', wantlist=True) | list }}"
# Images informations
- name: "Remove images tar"
local_action:
module: file
path: /tmp/risotto/images.tar
state: absent
- name: "Build images files"
local_action:
module: build_images
modules: "{{ vars['modules'] }}"
- name: "Compress images files"
local_action:
module: archive
path: "/tmp/risotto/images/"
dest: /tmp/risotto/images.tar
format: tar
- name: "Remove dest images files"
file:
path: /var/lib/risotto/images_files
state: absent
- name: "Create images files"
file:
path: /var/lib/risotto/images_files
state: directory
mode: "0700"
- name: "Copy images files"
unarchive:
src: "/tmp/risotto/images.tar"
dest: "/var/lib/risotto/images_files"