forked from stove/risotto
94 lines
3.1 KiB
YAML
94 lines
3.1 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
|
||
|
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
|
||
|
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 file[0].stat.checksum != file[1].stat.checksum else 'up to date' }}"
|
||
|
changed_when: not file[1].stat.exists or 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]['stat']['path'] }}"
|
||
|
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: "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"
|
||
|
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
|