forked from stove/risotto
121 lines
3.7 KiB
YAML
121 lines
3.7 KiB
YAML
- name: "Create SRV directory for {{ item.name}}"
|
|
when: "item.srv"
|
|
file: path=/var/lib/risotto/srv/{{ item.name }} state=directory mode=0755
|
|
|
|
- name: "Create SystemD directory for {{ item.name }}"
|
|
file: path=/var/lib/risotto/journals/{{ item.name }} state=directory mode=0755
|
|
|
|
- name: "Build machine files for {{ item.name }}"
|
|
rougail:
|
|
paths: "{{ vars[item.name]['services'] | fileslist }}"
|
|
root_local: "{{ host_install_dir }}"
|
|
root_remote: "/var/lib/risotto/configurations/{{ item.name }}"
|
|
hostname: "{{ item.name}}"
|
|
is_host: False
|
|
register: up_to_date_configuration
|
|
|
|
- name: "Change secrets right"
|
|
local_action:
|
|
module: file
|
|
path: "{{ host_install_dir }}/secrets"
|
|
state: directory
|
|
mode: 0700
|
|
|
|
- name: "Compress files for {{ item.name }}"
|
|
local_action:
|
|
module: archive
|
|
path: "{{ host_install_dir }}/"
|
|
dest: /tmp/new_configurations/{{ item.name }}
|
|
format: tar
|
|
when: up_to_date_configuration.changed
|
|
|
|
- name: "Build machine templates for {{ item.name }}"
|
|
rougail:
|
|
paths: "{{ vars[item.name]['services'] | fileslist }}"
|
|
root_local: "{{ host_install_dir }}"
|
|
root_remote: "/var/lib/risotto/configurations/{{ item.name }}"
|
|
hostname: "{{ item.name}}"
|
|
just_copy: true
|
|
is_host: False
|
|
when: copy_template
|
|
register: up_to_date_configuration
|
|
|
|
- name: "Compress templates for {{ item.name }}"
|
|
local_action:
|
|
module: archive
|
|
path: "../templates/"
|
|
dest: /tmp/new_templates/{{ item.name }}
|
|
format: tar
|
|
when: copy_template
|
|
|
|
- name: "Remove templates directory for {{ item.name }}"
|
|
file:
|
|
path: "/var/lib/risotto/templates/{{ item.name }}"
|
|
state: absent
|
|
when: copy_template
|
|
|
|
- name: "Create templates directory for {{ item.name }}"
|
|
file:
|
|
path: "/var/lib/risotto/templates/{{ item.name }}"
|
|
state: directory
|
|
when: copy_template
|
|
|
|
- name: "Copy templates for {{ item.name }}"
|
|
unarchive:
|
|
src: "/tmp/new_templates/{{ item.name }}"
|
|
dest: "/var/lib/risotto/templates/{{ item.name }}/"
|
|
when: copy_template
|
|
|
|
- name: "Remove old image {{ vars | modulename(item.name) }}"
|
|
file:
|
|
path: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}"
|
|
state: absent
|
|
when: delete_old_image == true
|
|
|
|
- name: "Stop machine {{ item.name }}"
|
|
machinectl:
|
|
state: stopped
|
|
machines: "{{ item.name }}"
|
|
when: delete_old_image == true
|
|
|
|
- name: "Remove old machine {{ item.name }}"
|
|
file:
|
|
path: /var/lib/machines/{{ item.name }}
|
|
state: absent
|
|
when: delete_old_image == true
|
|
|
|
- name: "Create system directory for {{ item.name }}"
|
|
file:
|
|
path: /var/lib/machines/{{ item.name }}
|
|
state: directory
|
|
register: system_directory_created
|
|
|
|
- name: "Check image for {{ item.name }}"
|
|
stat:
|
|
path: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}"
|
|
follow: true
|
|
register: register_name
|
|
when: system_directory_created.changed
|
|
|
|
#- name: Print return information from the previous task
|
|
# ansible.builtin.debug:
|
|
# var: register_name
|
|
|
|
- name: "Build image for {{ item.name }}"
|
|
ansible.builtin.shell: "/usr/local/sbin/build_image {{ vars | modulename(item.name) }}"
|
|
when: "'stat' in register_name and not register_name.stat.exists"
|
|
register: ret
|
|
failed_when: ret.rc != 0
|
|
|
|
- name: "Copy machine image for {{ item.name }}"
|
|
ansible.builtin.shell: "/usr/bin/cp -a --reflink=auto /var/lib/risotto/images/{{ vars | modulename(item.name) }}/* /var/lib/machines/{{ item.name }}"
|
|
when: system_directory_created.changed
|
|
|
|
- name: "Copy machine image version for {{ item.name }}"
|
|
ansible.builtin.copy:
|
|
src: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}.version"
|
|
remote_src: true
|
|
dest: "/var/lib/risotto/machines_versions/{{ item.name }}.version"
|
|
owner: "root"
|
|
group: "root"
|
|
when: system_directory_created.changed
|