Merge "tripleo-container-manage: fix duplicated loop vars"
This commit is contained in:
commit
b36e98a7ea
|
@ -14,14 +14,16 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
- name: "Get {{ lookup('dict', container_data).value.command.0 }} container status"
|
||||
- name: "Get {{ lookup('dict', container_exists_data).value.command.0 }} container status"
|
||||
set_fact:
|
||||
container_running: >-
|
||||
{{ podman_containers.containers | selectattr('Name', 'equalto', lookup('dict', container_data).value.command.0) |
|
||||
{{ podman_containers.containers | selectattr('Name', 'equalto', lookup('dict', container_exists_data).value.command.0) |
|
||||
map(attribute='State.Running') | first | default(false) }}
|
||||
|
||||
- name: "Fail if {{ lookup('dict', container_data).key }} is not running"
|
||||
- name: "Fail if {{ lookup('dict', container_exists_data).key }} is not running"
|
||||
fail:
|
||||
msg: "Can't run container exec for {{ lookup('dict', container_data).key }}, {{ lookup('dict', container_data).value.command.0 }} is not running"
|
||||
msg: >-
|
||||
Can't run container exec for {{ lookup('dict', container_exists_data).key }},
|
||||
{{ lookup('dict', container_exists_data).value.command.0 }} is not running
|
||||
when:
|
||||
- not container_running|default(false)|bool
|
||||
|
|
|
@ -18,23 +18,23 @@
|
|||
include_tasks: container_running.yml
|
||||
loop: "{{ batched_container_data | haskey(attribute='action', value='exec') }}"
|
||||
loop_control:
|
||||
loop_var: container_data
|
||||
loop_var: container_exists_data
|
||||
|
||||
- name: "Run actions async"
|
||||
command:
|
||||
argv: "{{ cmd_template + lookup('dict', container_data).value.command }}"
|
||||
argv: "{{ cmd_template + lookup('dict', container_exec_data).value.command }}"
|
||||
vars:
|
||||
cmd_template:
|
||||
- "{{ tripleo_container_manage_cli }}"
|
||||
- "exec"
|
||||
- "-u"
|
||||
- "{{ lookup('dict', container_data).value.user if lookup('dict', container_data).value.user is defined else 'root' }}"
|
||||
- "{{ lookup('dict', container_exec_data).value.user if lookup('dict', container_exec_data).value.user is defined else 'root' }}"
|
||||
async: 60
|
||||
poll: 0
|
||||
register: exec_async_results
|
||||
loop: "{{ batched_container_data | haskey(attribute='action', value='exec') }}"
|
||||
loop_control:
|
||||
loop_var: container_data
|
||||
loop_var: container_exec_data
|
||||
when: not ansible_check_mode|bool
|
||||
|
||||
- name: "Check podman exec status"
|
||||
|
|
|
@ -25,61 +25,61 @@
|
|||
when:
|
||||
- podman_drop_in.stat.exists
|
||||
|
||||
- name: Set container_name and container_data facts
|
||||
- name: Set container_name and container_sysd facts
|
||||
set_fact:
|
||||
container_name: "{{ lookup('dict', container_config).key }}"
|
||||
container_data: "{{ lookup('dict', container_config).value }}"
|
||||
container_sysd_name: "{{ lookup('dict', container_config).key }}"
|
||||
container_sysd_data: "{{ lookup('dict', container_config).value }}"
|
||||
|
||||
- name: "Start systemd service for {{ container_name }}"
|
||||
- name: "Start systemd service for {{ container_sysd_name }}"
|
||||
block:
|
||||
- name: "Remove trailing .requires for {{ container_name }}"
|
||||
- name: "Remove trailing .requires for {{ container_sysd_name }}"
|
||||
file:
|
||||
path: "/etc/systemd/system/tripleo_{{ container_name }}.requires"
|
||||
path: "/etc/systemd/system/tripleo_{{ container_sysd_name }}.requires"
|
||||
state: absent
|
||||
- name: "Create systemd unit file for {{ container_name }} service"
|
||||
- name: "Create systemd unit file for {{ container_sysd_name }} service"
|
||||
template:
|
||||
src: systemd-service.j2
|
||||
dest: "/etc/systemd/system/tripleo_{{ container_name }}.service"
|
||||
dest: "/etc/systemd/system/tripleo_{{ container_sysd_name }}.service"
|
||||
mode: '0644'
|
||||
owner: root
|
||||
group: root
|
||||
register: systemd_file
|
||||
- name: "Enable and start systemd service for {{ container_name }}"
|
||||
- name: "Enable and start systemd service for {{ container_sysd_name }}"
|
||||
systemd:
|
||||
# Restart the service if it was already running
|
||||
state: restarted
|
||||
name: "tripleo_{{ container_name }}.service"
|
||||
name: "tripleo_{{ container_sysd_name }}.service"
|
||||
enabled: true
|
||||
daemon_reload: true
|
||||
when:
|
||||
# Re-add podman_container.changed from async
|
||||
- systemd_file.changed
|
||||
- name: "Manage systemd healthcheck for {{ container_name }}"
|
||||
- name: "Manage systemd healthcheck for {{ container_sysd_name }}"
|
||||
when:
|
||||
- not tripleo_container_manage_healthcheck_disabled
|
||||
- container_data.healthcheck is defined
|
||||
- container_sysd_data.healthcheck is defined
|
||||
block:
|
||||
- name: "Create systemd unit file for {{ container_name }} healthcheck"
|
||||
- name: "Create systemd unit file for {{ container_sysd_name }} healthcheck"
|
||||
template:
|
||||
src: systemd-healthcheck.j2
|
||||
dest: "/etc/systemd/system/tripleo_{{ container_name }}_healthcheck.service"
|
||||
dest: "/etc/systemd/system/tripleo_{{ container_sysd_name }}_healthcheck.service"
|
||||
mode: '0644'
|
||||
owner: root
|
||||
group: root
|
||||
register: systemd_healthcheck
|
||||
- name: "Create systemd timer for {{ container_name }} healthcheck"
|
||||
- name: "Create systemd timer for {{ container_sysd_name }} healthcheck"
|
||||
template:
|
||||
src: systemd-timer.j2
|
||||
dest: "/etc/systemd/system/tripleo_{{ container_name }}_healthcheck.timer"
|
||||
dest: "/etc/systemd/system/tripleo_{{ container_sysd_name }}_healthcheck.timer"
|
||||
mode: '0644'
|
||||
owner: root
|
||||
group: root
|
||||
register: systemd_timer
|
||||
- name: "Enable and start systemd timer for {{ container_name }}"
|
||||
- name: "Enable and start systemd timer for {{ container_sysd_name }}"
|
||||
systemd:
|
||||
# Restart the timer if it was already running
|
||||
state: restarted
|
||||
name: "tripleo_{{ container_name }}_healthcheck.timer"
|
||||
name: "tripleo_{{ container_sysd_name }}_healthcheck.timer"
|
||||
enabled: true
|
||||
daemon_reload: true
|
||||
when:
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[Unit]
|
||||
Description=tripleo_{{ container_name }} healthcheck
|
||||
After=tripleo-container-shutdown.service tripleo_{{ container_name }}.service
|
||||
Requisite=tripleo_{{ container_name }}.service
|
||||
Description=tripleo_{{ container_sysd_name }} healthcheck
|
||||
After=tripleo-container-shutdown.service tripleo_{{ container_sysd_name }}.service
|
||||
Requisite=tripleo_{{ container_sysd_name }}.service
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/podman exec {{ container_name }} {{ container_data.healthcheck.test }}
|
||||
ExecStart=/usr/bin/podman exec {{ container_sysd_name }} {{ container_sysd_data.healthcheck.test }}
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
[Unit]
|
||||
Description={{ container_name }} container
|
||||
Description={{ container_sysd_name }} container
|
||||
After=tripleo-container-shutdown.service
|
||||
Wants={{ container_data.depends_on | default([]) | join(',') }}
|
||||
Wants={{ container_sysd_data.depends_on | default([]) | join(',') }}
|
||||
[Service]
|
||||
Restart=always
|
||||
{% if container_data.depends_on is defined and (container_data.depends_on | length > 0) and podman_drop_in | default('false') %}
|
||||
ExecStart=/usr/libexec/tripleo-start-podman-container {{ container_name }}
|
||||
{% if container_sysd_data.depends_on is defined and (container_sysd_data.depends_on | length > 0) and podman_drop_in | default('false') %}
|
||||
ExecStart=/usr/libexec/tripleo-start-podman-container {{ container_sysd_name }}
|
||||
{% else %}
|
||||
ExecStart=/usr/bin/podman start {{ container_name }}
|
||||
ExecStart=/usr/bin/podman start {{ container_sysd_name }}
|
||||
{% endif %}
|
||||
ExecStop=/usr/bin/podman stop -t {{ container_data.stop_grace_period | default(10) | int }} {{ container_name }}
|
||||
ExecStop=/usr/bin/podman stop -t {{ container_sysd_data.stop_grace_period | default(10) | int }} {{ container_sysd_name }}
|
||||
KillMode=none
|
||||
Type=forking
|
||||
PIDFile=/var/run/{{ container_name }}.pid
|
||||
{% if container_data.systemd_exec_flags is defined %}
|
||||
{% for s_flag, s_value in container_data.systemd_exec_flags.items() %}
|
||||
PIDFile=/var/run/{{ container_sysd_name }}.pid
|
||||
{% if container_sysd_data.systemd_exec_flags is defined %}
|
||||
{% for s_flag, s_value in container_sysd_data.systemd_exec_flags.items() %}
|
||||
{{ s_flag }}={{ s_value }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[Unit]
|
||||
Description=tripleo_{{ container_name }} container healthcheck
|
||||
PartOf=tripleo_{{ container_name }}.service
|
||||
Description=tripleo_{{ container_sysd_name }} container healthcheck
|
||||
PartOf=tripleo_{{ container_sysd_name }}.service
|
||||
[Timer]
|
||||
OnActiveSec=120
|
||||
OnUnitActiveSec={{ container_data.check_interval | default(60) }}
|
||||
RandomizedDelaySec={{ 45 if container_data.check_interval is not defined else (container_data.check_interval * 3 / 4) | int | abs }}
|
||||
OnUnitActiveSec={{ container_sysd_data.check_interval | default(60) }}
|
||||
RandomizedDelaySec={{ 45 if container_sysd_data.check_interval is not defined else (container_sysd_data.check_interval * 3 / 4) | int | abs }}
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
|
|
Loading…
Reference in New Issue