71 lines
2.0 KiB
YAML
71 lines
2.0 KiB
YAML
|
---
|
||
|
- name: create docker-mounted-files directory
|
||
|
ansible.builtin.file:
|
||
|
path: "/usr/local/docker-mounted-files/docker-sensors-polling"
|
||
|
state: directory
|
||
|
become: true
|
||
|
|
||
|
- name: Template sensors-polling conf.yml
|
||
|
ansible.builtin.template:
|
||
|
src: templates/sensors-polling-conf.yml.j2
|
||
|
dest: /usr/local/docker-mounted-files/docker-sensors-polling/conf.yml
|
||
|
become: true
|
||
|
|
||
|
- name: Build sensors-polling image
|
||
|
ansible.builtin.include_role:
|
||
|
name: role_build_container_image
|
||
|
vars:
|
||
|
image: "{{ item }}"
|
||
|
with_items:
|
||
|
- repo_url: https://git.scimetis.net/yohan/docker-sensors-polling.git
|
||
|
repo_name: docker-sensors-polling
|
||
|
name: sensors-polling
|
||
|
result_var: build_result
|
||
|
|
||
|
- debug: var=build_result
|
||
|
when: build_result.changed
|
||
|
|
||
|
- name: Gather facts on sensors-polling container
|
||
|
containers.podman.podman_container_info:
|
||
|
name: sensors-polling
|
||
|
register: container_info
|
||
|
become: true
|
||
|
|
||
|
- debug: var=container_info.containers[0].Config.Annotations.git_commit
|
||
|
when: container_info.containers | length == 1
|
||
|
|
||
|
- name: Set fact bool_recreate to true
|
||
|
set_fact:
|
||
|
bool_recreate: true
|
||
|
when:
|
||
|
- container_info.containers | length == 1
|
||
|
- container_info.containers[0].Config.Annotations.git_commit != commit
|
||
|
|
||
|
- name: Delete sensors-polling container
|
||
|
containers.podman.podman_container:
|
||
|
name: sensors-polling
|
||
|
state: absent
|
||
|
become: true
|
||
|
when: bool_recreate | default(false)
|
||
|
|
||
|
- name: Create sensors-polling container
|
||
|
containers.podman.podman_container:
|
||
|
name: sensors-polling
|
||
|
image: localhost/sensors-polling:latest
|
||
|
network:
|
||
|
- host
|
||
|
env:
|
||
|
TZ: "Europe/Paris"
|
||
|
privileged: true
|
||
|
restart_policy: always
|
||
|
volume:
|
||
|
- /usr/local/docker-mounted-files/docker-sensors-polling/conf.yml:/root/conf.yml
|
||
|
- /run/udev:/run/udev
|
||
|
become: true
|
||
|
when: bool_recreate | default(false) or container_info.containers | length == 0
|
||
|
|
||
|
- name: Prune images
|
||
|
containers.podman.podman_prune:
|
||
|
image: true
|
||
|
become: true
|