--- - name: "Populate service facts" service_facts: - name: "Packages installation" apt: pkg: "{{ vars[inventory_hostname]['general']['host_packages'] }}" update_cache: yes state: latest - name: "Build host files" rougail: paths: "{{ vars[inventory_hostname]['services'] | fileslist(is_host=True) }}" root_local: "{{ host_install_dir }}" root_remote: "/" hostname: "{{ inventory_hostname }}" is_host: True - name: "Create /usr/local/lib/systemd/system" file: path: /usr/local/lib/systemd/system state: directory mode: 0755 - name: "Copy service file only if not exists" 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'] and item.value['engine'] != 'none' copy: src: '{{ host_install_dir }}/usr/local/lib/systemd/system/{{ item.value["doc"] }}' force: no dest: '/usr/local/lib/systemd/system/{{ item.value["doc"] }}' loop: "{{ vars[inventory_hostname]['services'] | dict2items }}" loop_control: label: "{{ item.value['doc'] }}" - 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: "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: "{{ host_install_dir }}/{{ 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: "{{ host_install_dir }}/{{ 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" - name: "Create versions directory" file: path: /var/lib/risotto/machines_versions state: directory mode: "0700"