feat: add initial molecule with docker.
This commit is contained in:
parent
ffd51d6124
commit
af0ceadc13
@ -1,2 +1,29 @@
|
|||||||
---
|
---
|
||||||
# defaults file for laurivan.immich
|
# defaults file for laurivan.immich
|
||||||
|
|
||||||
|
immich_version: "release"
|
||||||
|
immich_port: "2283"
|
||||||
|
immich_upload: "./library"
|
||||||
|
|
||||||
|
immich_typesense_key: "SomeRandomKey"
|
||||||
|
immich_db_password: "postgres"
|
||||||
|
|
||||||
|
# immich-Controller paths
|
||||||
|
immich_root_path: /var/local
|
||||||
|
immich_data_base: "{{ immich_root_path }}/immich-controller"
|
||||||
|
immich_config_path: "{{ immich_root_path }}/conf/immich-controller"
|
||||||
|
immich_archives:
|
||||||
|
- "/mnt/multimedia/photos"
|
||||||
|
|
||||||
|
# Add other paths here to make sure they're created automatically
|
||||||
|
#
|
||||||
|
immich_skeleton_paths:
|
||||||
|
- "{{ immich_config_path }}"
|
||||||
|
|
||||||
|
# Add more templates to be copied into the config
|
||||||
|
immich_configuration_files:
|
||||||
|
- "docker-compose.yml"
|
||||||
|
- "env.immich.conf"
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
immich_documentation_link: "https://www.laurivan.com"
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
galaxy_info:
|
galaxy_info:
|
||||||
author: your name
|
author: Laur Ivan
|
||||||
description: your role description
|
description: Ansible role to install Immich
|
||||||
company: your company (optional)
|
role_name: immich
|
||||||
|
namespace: laurivan
|
||||||
|
|
||||||
# If the issue tracker for your role is not on github, uncomment the
|
# If the issue tracker for your role is not on github, uncomment the
|
||||||
# next line and provide a value
|
# next line and provide a value
|
||||||
@ -14,9 +15,9 @@ galaxy_info:
|
|||||||
# - GPL-3.0-only
|
# - GPL-3.0-only
|
||||||
# - Apache-2.0
|
# - Apache-2.0
|
||||||
# - CC-BY-4.0
|
# - CC-BY-4.0
|
||||||
license: license (GPL-2.0-or-later, MIT, etc)
|
license: MIT
|
||||||
|
|
||||||
min_ansible_version: 2.9
|
min_ansible_version: "2.9"
|
||||||
|
|
||||||
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||||
# min_ansible_container_version:
|
# min_ansible_container_version:
|
||||||
|
@ -1,8 +1,29 @@
|
|||||||
---
|
- name: Fail if molecule group is missing
|
||||||
|
hosts: localhost
|
||||||
|
tasks:
|
||||||
|
- name: Print some info
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ groups }}"
|
||||||
|
|
||||||
|
- name: Assert group existence
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'molecule' in groups"
|
||||||
|
fail_msg: |
|
||||||
|
molecule group was not found inside inventory groups: {{ groups }}
|
||||||
|
|
||||||
- name: Converge
|
- name: Converge
|
||||||
hosts: all
|
hosts: molecule
|
||||||
|
# We disable gather facts because it would fail due to our container not
|
||||||
|
# having python installed. This will not prevent use from running 'raw'
|
||||||
|
# commands. Most molecule users are expected to use containers that already
|
||||||
|
# have python installed in order to avoid notable delays installing it.
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: Replace this task with one that validates your content
|
- name: Check uname (converge)
|
||||||
ansible.builtin.debug:
|
ansible.builtin.raw: uname -a
|
||||||
msg: "This is the effective test"
|
register: result
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Print some info (converge)
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: result.stdout | regex_search("^Linux")
|
||||||
|
@ -1,36 +1,79 @@
|
|||||||
---
|
|
||||||
- name: Create
|
- name: Create
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
connection: local
|
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
# no_log: "{{ molecule_no_log }}"
|
vars:
|
||||||
|
molecule_inventory:
|
||||||
|
all:
|
||||||
|
hosts: {}
|
||||||
|
molecule: {}
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: Create a container
|
||||||
|
community.docker.docker_container:
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
image: "{{ item.image }}"
|
||||||
|
state: started
|
||||||
|
command: sleep 1d
|
||||||
|
log_driver: json-file
|
||||||
|
register: result
|
||||||
|
loop: "{{ molecule_yml.platforms }}"
|
||||||
|
|
||||||
# TODO: Developer must implement and populate 'server' variable
|
- name: Print some container info
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ result.results }}"
|
||||||
|
|
||||||
- name: Create instance config
|
- name: Fail if container is not running
|
||||||
when: server.changed | default(false) | bool # noqa no-handler
|
when: >
|
||||||
block:
|
item.container.State.ExitCode != 0 or
|
||||||
- name: Populate instance config dict # noqa jinja
|
not item.container.State.Running
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.include_tasks:
|
||||||
instance_conf_dict: {}
|
file: tasks/create-fail.yml
|
||||||
# instance': "{{ }}",
|
loop: "{{ result.results }}"
|
||||||
# address': "{{ }}",
|
loop_control:
|
||||||
# user': "{{ }}",
|
label: "{{ item.container.Name }}"
|
||||||
# port': "{{ }}",
|
|
||||||
# 'identity_file': "{{ }}", }
|
|
||||||
with_items: "{{ server.results }}"
|
|
||||||
register: instance_config_dict
|
|
||||||
|
|
||||||
- name: Convert instance config dict to a list
|
- name: Add container to molecule_inventory
|
||||||
ansible.builtin.set_fact:
|
vars:
|
||||||
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
|
inventory_partial_yaml: |
|
||||||
|
all:
|
||||||
|
children:
|
||||||
|
molecule:
|
||||||
|
hosts:
|
||||||
|
"{{ item.name }}":
|
||||||
|
ansible_connection: community.docker.docker
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
molecule_inventory: >
|
||||||
|
{{ molecule_inventory | combine(inventory_partial_yaml | from_yaml, recursive=true) }}
|
||||||
|
loop: "{{ molecule_yml.platforms }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.name }}"
|
||||||
|
|
||||||
- name: Dump instance config
|
- name: Dump molecule_inventory
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: |
|
content: |
|
||||||
# Molecule managed
|
{{ molecule_inventory | to_yaml }}
|
||||||
|
dest: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
|
||||||
|
mode: "0600"
|
||||||
|
|
||||||
{{ instance_conf | to_json | from_json | to_yaml }}
|
- name: Force inventory refresh
|
||||||
dest: "{{ molecule_instance_config }}"
|
ansible.builtin.meta: refresh_inventory
|
||||||
mode: 0600
|
|
||||||
|
- name: Fail if molecule group is missing
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: "'molecule' in groups"
|
||||||
|
fail_msg: |
|
||||||
|
molecule group was not found inside inventory groups: {{ groups }}
|
||||||
|
run_once: true # noqa: run-once[task]
|
||||||
|
|
||||||
|
# we want to avoid errors like "Failed to create temporary directory"
|
||||||
|
- name: Validate that inventory was refreshed
|
||||||
|
hosts: molecule
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Check uname
|
||||||
|
ansible.builtin.raw: uname -a
|
||||||
|
register: result
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Display uname info
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ result.stdout }}"
|
||||||
|
@ -1,24 +1,19 @@
|
|||||||
---
|
- name: Destroy molecule containers
|
||||||
- name: Destroy
|
hosts: molecule
|
||||||
hosts: localhost
|
|
||||||
connection: local
|
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
# no_log: "{{ molecule_no_log }}"
|
|
||||||
tasks:
|
tasks:
|
||||||
# Developer must implement.
|
- name: Stop and remove container
|
||||||
|
delegate_to: localhost
|
||||||
|
community.docker.docker_container:
|
||||||
|
name: "{{ inventory_hostname }}"
|
||||||
|
state: absent
|
||||||
|
auto_remove: true
|
||||||
|
|
||||||
# Mandatory configuration for Molecule to function.
|
- name: Remove dynamic molecule inventory
|
||||||
|
hosts: localhost
|
||||||
- name: Populate instance config
|
gather_facts: false
|
||||||
ansible.builtin.set_fact:
|
tasks:
|
||||||
instance_conf: {}
|
- name: Remove dynamic inventory file
|
||||||
|
ansible.builtin.file:
|
||||||
- name: Dump instance config
|
path: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
|
||||||
ansible.builtin.copy:
|
state: absent
|
||||||
content: |
|
|
||||||
# Molecule managed
|
|
||||||
|
|
||||||
{{ instance_conf | to_json | from_json | to_yaml }}
|
|
||||||
dest: "{{ molecule_instance_config }}"
|
|
||||||
mode: 0600
|
|
||||||
when: server.changed | default(false) | bool # noqa no-handler
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
options:
|
||||||
|
requirements-file: molecule/default/requirements.yml
|
||||||
platforms:
|
platforms:
|
||||||
- name: instance
|
- name: molecule-ubuntu
|
||||||
# you might want to add your own variables here based on what provisioning
|
image: ubuntu:18.04
|
||||||
# you are doing like:
|
|
||||||
# image: quay.io/centos/centos:stream8
|
|
||||||
|
2
molecule/default/requirements.yml
Normal file
2
molecule/default/requirements.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
collections:
|
||||||
|
- community.docker
|
13
molecule/default/tasks/create-fail.yml
Normal file
13
molecule/default/tasks/create-fail.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
- name: Retrieve container log
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: >-
|
||||||
|
{% raw %}
|
||||||
|
docker logs
|
||||||
|
{% endraw %}
|
||||||
|
{{ item.stdout_lines[0] }}
|
||||||
|
changed_when: false
|
||||||
|
register: logfile_cmd
|
||||||
|
|
||||||
|
- name: Display container log
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "{{ logfile_cmd.stderr }}"
|
Loading…
Reference in New Issue
Block a user