forked from stove/risotto
114 lines
4 KiB
YAML
114 lines
4 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 }}"
|
|
local_action:
|
|
module: rougail
|
|
hostname: "{{ item.name}}"
|
|
is_host: False
|
|
|
|
- name: "Get local informations for {{ item.name }} configuration's file"
|
|
local_action:
|
|
module: stat
|
|
path: "installations{{ file.name }}"
|
|
checksum: sha256
|
|
get_checksum: yes
|
|
follow: true
|
|
loop: "{{ vars[item.name]['services'] | fileslist }}"
|
|
loop_control:
|
|
loop_var: file
|
|
label: "{{ file.name }}"
|
|
register: local_configuration
|
|
|
|
- name: "Get remote informations for {{ item.name }} configuration's file"
|
|
stat:
|
|
path: "/var/lib/risotto/configurations/{{ item.name }}{{ file.name }}"
|
|
checksum: sha256
|
|
get_checksum: yes
|
|
follow: true
|
|
loop: "{{ vars[item.name]['services'] | fileslist }}"
|
|
loop_control:
|
|
loop_var: file
|
|
label: "{{ file.name }}"
|
|
register: remote_configuration
|
|
|
|
- name: "Configuration's file is up to date in {{ item.name }}"
|
|
debug:
|
|
msg: "file is {{ 'out of date' if not file[1].stat.exists or (not 'checksum' in file[0].stat and 'checksum' in file[1].stat) or ('checksum' in file[0].stat and not 'checksum' in file[1].stat) or ('checksum' in file[0].stat and 'checksum' in file[1].stat and file[0].stat.checksum != file[1].stat.checksum) else 'up to date' }}"
|
|
changed_when: not file[1].stat.exists or (not 'checksum' in file[0].stat and 'checksum' in file[1].stat) or ('checksum' in file[0].stat and not 'checksum' in file[1].stat) or ('checksum' in file[0].stat and 'checksum' in file[1].stat and file[0].stat.checksum != file[1].stat.checksum)
|
|
loop: "{{ local_configuration.results | zip(remote_configuration.results) | list }}"
|
|
loop_control:
|
|
loop_var: file
|
|
label: "{{ file[0]['file']['name'] }}"
|
|
ignore_errors: true
|
|
register: up_to_date_configuration
|
|
|
|
- name: "Remove Compressed files for {{ item.name }}"
|
|
local_action:
|
|
module: file
|
|
path: /tmp/new_configurations/{{ item.name }}
|
|
state: absent
|
|
when: up_to_date_configuration.changed
|
|
|
|
- name: "Compress files for {{ item.name }}"
|
|
local_action:
|
|
module: archive
|
|
path: "installations/"
|
|
dest: /tmp/new_configurations/{{ item.name }}
|
|
format: tar
|
|
when: up_to_date_configuration.changed
|
|
|
|
- name: "Remove old image {{ vars | modulename(item.name) }}"
|
|
file:
|
|
path: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}.tar"
|
|
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) }}.tar"
|
|
follow: true
|
|
register: register_name
|
|
when: system_directory_created.changed
|
|
|
|
- name: "Build image for {{ item.name }}"
|
|
ansible.builtin.shell: "/usr/local/sbin/build_image {{ vars | modulename(item.name) }}"
|
|
when: system_directory_created.changed and not register_name.stat.exists
|
|
|
|
- name: "Uncompress machine image for {{ item.name }}"
|
|
unarchive:
|
|
src: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}.tar"
|
|
remote_src: true
|
|
dest: /var/lib/machines/{{ item.name }}/
|
|
when: system_directory_created.changed
|
|
|
|
- name: "SHA machine image for {{ item.name }}"
|
|
ansible.builtin.copy:
|
|
src: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}.tar.sha"
|
|
remote_src: true
|
|
dest: "/var/lib/risotto/configurations/sha/{{ item.name }}.sha"
|
|
owner: "root"
|
|
group: "root"
|
|
when: system_directory_created.changed
|