risotto/ansible/machine.yml

122 lines
3.7 KiB
YAML
Raw Normal View History

2022-10-01 22:33:11 +02:00
- 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 }}"
2022-12-21 16:35:58 +01:00
rougail:
paths: "{{ vars[item.name]['services'] | fileslist }}"
root_local: "{{ host_install_dir }}"
root_remote: "/var/lib/risotto/configurations/{{ item.name }}"
2022-10-01 22:33:11 +02:00
hostname: "{{ item.name}}"
is_host: False
register: up_to_date_configuration
2022-12-21 16:35:58 +01:00
- name: "Change secrets right"
2022-10-01 22:33:11 +02:00
local_action:
module: file
2022-12-21 16:35:58 +01:00
path: "{{ host_install_dir }}/secrets"
state: directory
mode: 0700
2022-10-01 22:33:11 +02:00
- name: "Compress files for {{ item.name }}"
local_action:
module: archive
2022-12-21 16:35:58 +01:00
path: "{{ host_install_dir }}/"
2022-10-01 22:33:11 +02:00
dest: /tmp/new_configurations/{{ item.name }}
format: tar
when: up_to_date_configuration.changed
2022-12-21 16:35:58 +01:00
- 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:
2022-12-21 16:35:58 +01:00
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
2022-10-01 22:33:11 +02:00
- 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:
2022-12-21 16:35:58 +01:00
path: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}"
follow: true
2022-10-01 22:33:11 +02:00
register: register_name
when: system_directory_created.changed
2022-12-21 16:35:58 +01:00
#- name: Print return information from the previous task
# ansible.builtin.debug:
# var: register_name
2022-10-01 22:33:11 +02:00
- name: "Build image for {{ item.name }}"
ansible.builtin.shell: "/usr/local/sbin/build_image {{ vars | modulename(item.name) }}"
2022-12-21 16:35:58 +01:00
when: "'stat' in register_name and not register_name.stat.exists"
register: ret
failed_when: ret.rc != 0
2022-10-01 22:33:11 +02:00
2022-12-21 16:35:58 +01:00
- 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 }}"
2022-10-01 22:33:11 +02:00
when: system_directory_created.changed
2022-12-21 16:35:58 +01:00
- name: "Copy machine image version for {{ item.name }}"
2022-10-01 22:33:11 +02:00
ansible.builtin.copy:
2022-12-21 16:35:58 +01:00
src: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}.version"
2022-10-01 22:33:11 +02:00
remote_src: true
2022-12-21 16:35:58 +01:00
dest: "/var/lib/risotto/machines_versions/{{ item.name }}.version"
2022-10-01 22:33:11 +02:00
owner: "root"
group: "root"
when: system_directory_created.changed