diff --git a/meta/main.yml b/meta/main.yml index 42c3c1a..6048187 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -12,6 +12,7 @@ galaxy_info: versions: - focal - jammy + - noble - name: Debian versions: - bullseye diff --git a/molecule/default_vagrant/converge.yml b/molecule/default_os/converge.yml similarity index 100% rename from molecule/default_vagrant/converge.yml rename to molecule/default_os/converge.yml diff --git a/molecule/default_vagrant/group_vars/all.yml b/molecule/default_os/group_vars/all.yml similarity index 90% rename from molecule/default_vagrant/group_vars/all.yml rename to molecule/default_os/group_vars/all.yml index 359ff70..768ded5 100644 --- a/molecule/default_vagrant/group_vars/all.yml +++ b/molecule/default_os/group_vars/all.yml @@ -3,7 +3,7 @@ docker_systemd_service_container_name: "nginx" docker_systemd_service_image: nginx docker_systemd_service_container_env: {} docker_systemd_service_container_pull_image: true -docker_systemd_service_container_pull_force_source: true +docker_systemd_service_container_pull_force_source: false docker_systemd_service_flags: [] docker_systemd_service_container_cmd: [] docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container" diff --git a/molecule/default_os/molecule.yml b/molecule/default_os/molecule.yml new file mode 100644 index 0000000..548be71 --- /dev/null +++ b/molecule/default_os/molecule.yml @@ -0,0 +1,48 @@ +--- +dependency: + name: galaxy + options: + requirements-file: ./requirements.yml +driver: + name: openstack +platforms: + - name: instance.example.com + description: Molecule test instance. + flavor: a2-ram4-disk20-perf1 + image: Debian 12 bookworm + user: debian + network: + name: pcp-w3rxsrj-backend-network + create: false + security_group: + name: molecule__docker_systemd_service__with_custom_flags_os + create: true + description: Molecule test security group. + rules: + - proto: tcp + port: -1 + port_min: 0 + port_max: 0 + cidr: 0.0.0.0/0 + type: IPv4 +provisioner: + name: ansible + config_options: + defaults: + remote_tmp: /tmp/.ansible +verifier: + name: ansible +scenario: + name: default_os + test_sequence: + - dependency + - cleanup + - destroy + - syntax + - create + - prepare + - converge + - idempotence + - verify + - cleanup + - destroy diff --git a/molecule/default_vagrant/prepare.yml b/molecule/default_os/prepare.yml similarity index 100% rename from molecule/default_vagrant/prepare.yml rename to molecule/default_os/prepare.yml diff --git a/molecule/default_vagrant/requirements.yml b/molecule/default_os/requirements.yml similarity index 100% rename from molecule/default_vagrant/requirements.yml rename to molecule/default_os/requirements.yml diff --git a/molecule/default_vagrant/verify.yml b/molecule/default_os/verify.yml similarity index 100% rename from molecule/default_vagrant/verify.yml rename to molecule/default_os/verify.yml diff --git a/molecule/default_vagrant/molecule.yml b/molecule/default_vagrant/molecule.yml deleted file mode 100644 index 2b02360..0000000 --- a/molecule/default_vagrant/molecule.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- -dependency: - name: galaxy - options: - requirements-file: ./requirements.yml -driver: - name: vagrant - provider: - name: libvirt -platforms: - - name: instance - box: generic/${MOLECULE_TEST_OS} - cpus: 4 - memory: 4096 -provisioner: - name: ansible - config_options: - defaults: - remote_tmp: /tmp/.ansible -verifier: - name: ansible -scenario: - name: default_vagrant - test_sequence: - - dependency - - cleanup - - destroy - - syntax - - create - - prepare - - converge - - idempotence - - verify - - cleanup - - destroy diff --git a/molecule/with_custom_flags_vagrant/converge.yml b/molecule/with_custom_flags_os/converge.yml similarity index 100% rename from molecule/with_custom_flags_vagrant/converge.yml rename to molecule/with_custom_flags_os/converge.yml diff --git a/molecule/with_custom_flags_vagrant/group_vars/all.yml b/molecule/with_custom_flags_os/group_vars/all.yml similarity index 85% rename from molecule/with_custom_flags_vagrant/group_vars/all.yml rename to molecule/with_custom_flags_os/group_vars/all.yml index 0c8909c..405fd2f 100644 --- a/molecule/with_custom_flags_vagrant/group_vars/all.yml +++ b/molecule/with_custom_flags_os/group_vars/all.yml @@ -1,10 +1,10 @@ --- docker_systemd_service_container_name: "nginx" -docker_systemd_service_image: nginx +docker_systemd_service_image: nginx:1.27 docker_systemd_service_container_env: TEST_ENV: test docker_systemd_service_container_pull_image: true -docker_systemd_service_container_pull_force_source: true +docker_systemd_service_container_pull_force_source: false docker_systemd_service_flags: - privileged - network: host diff --git a/molecule/with_custom_flags_os/molecule.yml b/molecule/with_custom_flags_os/molecule.yml new file mode 100644 index 0000000..d35efaf --- /dev/null +++ b/molecule/with_custom_flags_os/molecule.yml @@ -0,0 +1,48 @@ +--- +dependency: + name: galaxy + options: + requirements-file: ./requirements.yml +driver: + name: openstack +platforms: + - name: instance.example.com + description: Molecule test instance. + flavor: a2-ram4-disk20-perf1 + image: Debian 12 bookworm + user: debian + network: + name: pcp-w3rxsrj-backend-network + create: false + security_group: + name: molecule__docker_systemd_service__with_custom_flags_os + create: true + description: Molecule test security group. + rules: + - proto: tcp + port: -1 + port_min: 0 + port_max: 0 + cidr: 0.0.0.0/0 + type: IPv4 +provisioner: + name: ansible + config_options: + defaults: + remote_tmp: /tmp/.ansible +verifier: + name: ansible +scenario: + name: with_custom_flags_os + test_sequence: + - dependency + - cleanup + - destroy + - syntax + - create + - prepare + - converge + - idempotence + - verify + - cleanup + - destroy diff --git a/molecule/with_custom_flags_vagrant/prepare.yml b/molecule/with_custom_flags_os/prepare.yml similarity index 100% rename from molecule/with_custom_flags_vagrant/prepare.yml rename to molecule/with_custom_flags_os/prepare.yml diff --git a/molecule/with_custom_flags_vagrant/requirements.yml b/molecule/with_custom_flags_os/requirements.yml similarity index 100% rename from molecule/with_custom_flags_vagrant/requirements.yml rename to molecule/with_custom_flags_os/requirements.yml diff --git a/molecule/with_custom_flags_vagrant/verify.yml b/molecule/with_custom_flags_os/verify.yml similarity index 100% rename from molecule/with_custom_flags_vagrant/verify.yml rename to molecule/with_custom_flags_os/verify.yml diff --git a/molecule/with_custom_flags_vagrant/molecule.yml b/molecule/with_custom_flags_vagrant/molecule.yml deleted file mode 100644 index fe55051..0000000 --- a/molecule/with_custom_flags_vagrant/molecule.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- -dependency: - name: galaxy - options: - requirements-file: ./requirements.yml -driver: - name: vagrant - provider: - name: libvirt -platforms: - - name: instance - box: generic/${MOLECULE_TEST_OS} - cpus: 4 - memory: 4096 -provisioner: - name: ansible - config_options: - defaults: - remote_tmp: /tmp/.ansible -verifier: - name: ansible -scenario: - name: with_custom_flags_vagrant - test_sequence: - - dependency - - cleanup - - destroy - - syntax - - create - - prepare - - converge - - idempotence - - verify - - cleanup - - destroy diff --git a/tasks/install.yml b/tasks/install.yml index c62cc6f..038fcb9 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,32 +1,41 @@ --- # task/install file for docker_systemd_service -- name: "Create ENV file(s) for docker service(s)" +- name: "Docker systemd service | Create ENV file(s) for docker service(s)" ansible.builtin.template: src: env.j2 dest: "{{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }}" owner: root group: root mode: '0600' - notify: systemctl-restart-service + register: _docker_systemd_service_env_file -- name: "Pull docker image(s)" +- name: "Docker systemd service | Pull docker image(s)" community.docker.docker_image: name: "{{ docker_systemd_service_image }}" force_source: "{{ docker_systemd_service_container_pull_force_source | bool }}" source: pull + register: _docker_systemd_service_image_pull when: docker_systemd_service_container_pull_image - notify: systemctl-restart-service -- name: "Create unit file(s) for service(s)" +- name: "Docker systemd service | Create unit file(s) for service(s)" ansible.builtin.template: src: unit.j2 dest: "/etc/systemd/system/{{ docker_systemd_service_name }}.service" owner: root group: root mode: '0644' - notify: systemctl-restart-service + registr: _docker_systemd_service_unit_file -- name: "Enable and start service(s)" +- name: "Docker systemd service | Set reload-check & restart-check variable" + ansible.builtin.set_fact: + _docker_systemd_service_need_daemon_reload: >- + {{ _docker_systemd_service_unit_file.changed | bool }} + _docker_systemd_service_need_restart: true + when: _docker_systemd_service_env_file.changed or + _docker_systemd_service_unit_file.changed or + docker_systemd_service_container_pull_image.changed + +- name: "Docker systemd service | Enable and start service(s)" ansible.builtin.systemd: name: '{{ docker_systemd_service_name }}.service' daemon_reload: true diff --git a/tasks/main.yml b/tasks/main.yml index 77d46d7..8c0b22a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,9 +1,31 @@ --- # task/main file for docker_systemd_service -- name: "Import install.yml" +- name: "Docker systemd service | Set reload-check & restart-check variable" + ansible.builtin.set_fact: + _docker_systemd_service_need_daemon_reload: false + _docker_systemd_service_need_restart: false + +- name: "Docker systemd service | Import install.yml" ansible.builtin.include_tasks: install.yml when: docker_systemd_service_state != "absent" -- name: "Import uninstall.yml" +- name: "Docker systemd service | Import uninstall.yml" ansible.builtin.include_tasks: uninstall.yml when: docker_systemd_service_state == "absent" + +- name: "Docker systemd service | Enable service: {{ docker_systemd_service_name }}" + ansible.builtin.service: + name: "{{ docker_systemd_service_name }}" + enabled: true + +- name: "Docker systemd service | Reload systemd daemon" + ansible.builtin.systemd: + daemon_reload: true + when: _docker_systemd_service_need_daemon_reload + +- name: "Docker systemd service | Start service: {{ docker_systemd_service_name }}" + ansible.builtin.service: + name: "{{ docker_systemd_service_name }}" + state: restarted + throttle: 1 + when: _docker_systemd_service_need_restart diff --git a/templates/env.j2 b/templates/env.j2 index f5e5931..cb4fd2c 100644 --- a/templates/env.j2 +++ b/templates/env.j2 @@ -1,3 +1,3 @@ {% for k,v in docker_systemd_service_container_env|dictsort %} {{ k }}={{ v }} -{% endfor %} \ No newline at end of file +{% endfor %}