fix: handlers running in unpredictable ways
this patch adds support for in-role management of reload and restarts of the systemd service it also adds support for ubuntu 24
This commit is contained in:
parent
fee75fb57c
commit
f39e1f95d0
@ -12,6 +12,7 @@ galaxy_info:
|
|||||||
versions:
|
versions:
|
||||||
- focal
|
- focal
|
||||||
- jammy
|
- jammy
|
||||||
|
- noble
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
- bullseye
|
- bullseye
|
||||||
|
@ -3,7 +3,7 @@ docker_systemd_service_container_name: "nginx"
|
|||||||
docker_systemd_service_image: nginx
|
docker_systemd_service_image: nginx
|
||||||
docker_systemd_service_container_env: {}
|
docker_systemd_service_container_env: {}
|
||||||
docker_systemd_service_container_pull_image: true
|
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_flags: []
|
||||||
docker_systemd_service_container_cmd: []
|
docker_systemd_service_container_cmd: []
|
||||||
docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container"
|
docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container"
|
48
molecule/default_os/molecule.yml
Normal file
48
molecule/default_os/molecule.yml
Normal file
@ -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
|
@ -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
|
|
@ -1,10 +1,10 @@
|
|||||||
---
|
---
|
||||||
docker_systemd_service_container_name: "nginx"
|
docker_systemd_service_container_name: "nginx"
|
||||||
docker_systemd_service_image: nginx
|
docker_systemd_service_image: nginx:1.27
|
||||||
docker_systemd_service_container_env:
|
docker_systemd_service_container_env:
|
||||||
TEST_ENV: test
|
TEST_ENV: test
|
||||||
docker_systemd_service_container_pull_image: true
|
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_flags:
|
||||||
- privileged
|
- privileged
|
||||||
- network: host
|
- network: host
|
48
molecule/with_custom_flags_os/molecule.yml
Normal file
48
molecule/with_custom_flags_os/molecule.yml
Normal file
@ -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
|
@ -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
|
|
@ -1,32 +1,41 @@
|
|||||||
---
|
---
|
||||||
# task/install file for docker_systemd_service
|
# 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:
|
ansible.builtin.template:
|
||||||
src: env.j2
|
src: env.j2
|
||||||
dest: "{{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }}"
|
dest: "{{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }}"
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: '0600'
|
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:
|
community.docker.docker_image:
|
||||||
name: "{{ docker_systemd_service_image }}"
|
name: "{{ docker_systemd_service_image }}"
|
||||||
force_source: "{{ docker_systemd_service_container_pull_force_source | bool }}"
|
force_source: "{{ docker_systemd_service_container_pull_force_source | bool }}"
|
||||||
source: pull
|
source: pull
|
||||||
|
register: _docker_systemd_service_image_pull
|
||||||
when: docker_systemd_service_container_pull_image
|
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:
|
ansible.builtin.template:
|
||||||
src: unit.j2
|
src: unit.j2
|
||||||
dest: "/etc/systemd/system/{{ docker_systemd_service_name }}.service"
|
dest: "/etc/systemd/system/{{ docker_systemd_service_name }}.service"
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: '0644'
|
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:
|
ansible.builtin.systemd:
|
||||||
name: '{{ docker_systemd_service_name }}.service'
|
name: '{{ docker_systemd_service_name }}.service'
|
||||||
daemon_reload: true
|
daemon_reload: true
|
||||||
|
@ -1,9 +1,31 @@
|
|||||||
---
|
---
|
||||||
# task/main file for docker_systemd_service
|
# 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
|
ansible.builtin.include_tasks: install.yml
|
||||||
when: docker_systemd_service_state != "absent"
|
when: docker_systemd_service_state != "absent"
|
||||||
|
|
||||||
- name: "Import uninstall.yml"
|
- name: "Docker systemd service | Import uninstall.yml"
|
||||||
ansible.builtin.include_tasks: uninstall.yml
|
ansible.builtin.include_tasks: uninstall.yml
|
||||||
when: docker_systemd_service_state == "absent"
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user