# 2023-09-25 # Tasks: stacks --- - ansible.builtin.include_vars: ../vm/vars/vault/domain.yml - ansible.builtin.include_vars: ../vm/vars/vault/vm.yml - ansible.builtin.include_vars: ../vm/vars/vault/ports.yml - ansible.builtin.include_vars: ../vm/vars/vm.yml - ansible.builtin.include_vars: composes/vars/vault/ssl.yml - ansible.builtin.include_vars: stacks.yml - name: Preload composes required vars ansible.builtin.include_vars: file: ../composes/vars/common.yml tags: - stacks - composes - import when: - ansible_facts['system'] == "Linux" - name: Include all .yml stacks definition ansible.builtin.include_vars: dir: ../composes/inventory depth: 1 extensions: - "yml" tags: - stacks - composes - import when: - ansible_facts['system'] == "Linux" - name: Merging common & vm stacks ansible.builtin.set_fact: stacks: "{{ stacks_common + stacks_vm }}" when: - ansible_facts['system'] == "Linux" tags: - stacks - composes - merge - name: Create all stacks main directories ansible.builtin.file: path: "{{ vm_docker_root }}/{{ item.name }}" owner: "{{ stack_owner }}" group: "{{ stack_group }}" state: directory mode: u=rwx,g=rx,o=rx with_items: - "{{ stacks }}" when: - ansible_facts['system'] == "Linux" tags: - stacks - directories - create - name: Create each stack .env symlinks ansible.builtin.file: src: "../{{ vm_include_folder }}/{{ vm_template_env_name }}" dest: "{{ vm_docker_root }}/{{ item.name }}/{{ vm_template_env_name }}" owner: "{{ stack_owner }}" group: "{{ stack_group }}" state: link mode: u=rw,g=r,o=r with_items: - "{{ stacks }}" when: - ansible_facts['system'] == "Linux" tags: - stacks - symlinks - create - name: Create directories required by each stack (directories keyword) ansible.builtin.file: # item.0.name : folder # item.1 : stack name path: "{{ vm_docker_root }}/{{ item.0.name }}/{{ item.1 }}" owner: "{{ stack_owner }}" group: "{{ stack_group }}" state: directory mode: u=rwx,g=rx,o=rx with_subelements: - "{{ stacks | selectattr('directories', 'defined') }}" - directories - skip_missing: true when: - ansible_facts['system'] == "Linux" tags: - stacks - stack - directories - create - name: Create each stack docker-compose.yml files ansible.builtin.template: lstrip_blocks: true trim_blocks: true backup: yes src: "{{ template_docker_compose }}" dest: "{{ vm_docker_root }}/{{ item.name }}/{{ template_docker_compose_name }}" owner: "{{ stack_owner }}" group: "{{ stack_group }}" mode: u=rw,g=r,o=r with_items: - "{{ stacks }}" when: - ansible_facts['system'] == "Linux" tags: - stacks - stack - symlinks - create - name: Execute stack specific tasks ansible.builtin.include_tasks: # item.0.name : stack # item.1 : task file file: "{{ stack_specific_task_directory }}/{{ item.1 }}" apply: tags: - stacks - task - execute with_subelements: - "{{ stacks | selectattr('tasks', 'defined')}}" - tasks - skip_missing: true when: - ansible_facts['system'] == "Linux" tags: - stacks - stack - tasks - name: Find availables stacks find: paths: "{{ vm_docker_root }}" file_type: directory recurse: no excludes: "{{ vm_include_folder }}" register: folders - name: Compute available stacks list no_log: true set_fact: availables: "{{ availables + [item.path |basename]}}" with_items: "{{ folders.files }}" - name: Update available stacks ansible.builtin.lineinfile: path: "{{ vm_template_root_vm }}/{{ vm_stack_available }}" line: "{{ item }}" with_items: - "{{ availables |sort }}" when: - ansible_facts['system'] == "Linux" tags: - stacks - available - update