forked from jakub/ansible
.
This commit is contained in:
@@ -54,12 +54,11 @@
|
|||||||
state: present
|
state: present
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
- name: Run Homarr update commands on VM (via SSH)
|
- name: Run Homarr update commands on VM (via SSH) # use SSHPASS env, hide item label
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
- sshpass
|
- sshpass
|
||||||
- -p
|
- -e # read password from SSHPASS environment
|
||||||
- "{{ vm_pass }}"
|
|
||||||
- ssh
|
- ssh
|
||||||
- -o
|
- -o
|
||||||
- StrictHostKeyChecking=no
|
- StrictHostKeyChecking=no
|
||||||
@@ -69,10 +68,15 @@
|
|||||||
- bash
|
- bash
|
||||||
- -lc
|
- -lc
|
||||||
- "{{ ('sudo ' if use_sudo else '') + item }}"
|
- "{{ ('sudo ' if use_sudo else '') + item }}"
|
||||||
|
environment:
|
||||||
|
SSHPASS: "{{ vm_pass }}" # supply password via environment
|
||||||
loop: "{{ homarr_commands }}"
|
loop: "{{ homarr_commands }}"
|
||||||
|
loop_control:
|
||||||
|
index_var: idx # capture loop index
|
||||||
|
label: "cmd-{{ idx }}" # avoid printing full command in (item=...) line
|
||||||
register: homarr_cmds
|
register: homarr_cmds
|
||||||
changed_when: false
|
changed_when: false
|
||||||
no_log: "{{ DEBUG == 0 }}"
|
no_log: "{{ DEBUG == 0 }}" # hide outputs and env when not debugging
|
||||||
|
|
||||||
- name: Show outputs for each Homarr command
|
- name: Show outputs for each Homarr command
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
@@ -86,12 +90,15 @@
|
|||||||
loop: "{{ homarr_cmds.results }}"
|
loop: "{{ homarr_cmds.results }}"
|
||||||
when: DEBUG == 1
|
when: DEBUG == 1
|
||||||
|
|
||||||
- name: Fail play if any Homarr command failed
|
- name: Fail play if any Homarr command failed # also hide item label
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that: "item.rc == 0"
|
that: "item.rc == 0"
|
||||||
fail_msg: "Homarr update failed on VM: {{ item.item }} (rc={{ item.rc }})"
|
fail_msg: "Homarr update failed on VM: {{ item.item }} (rc={{ item.rc }})"
|
||||||
success_msg: "All Homarr update commands succeeded."
|
success_msg: "All Homarr update commands succeeded."
|
||||||
loop: "{{ homarr_cmds.results }}"
|
loop: "{{ homarr_cmds.results }}"
|
||||||
|
loop_control:
|
||||||
|
index_var: idx
|
||||||
|
label: "cmd-{{ idx }}"
|
||||||
|
|
||||||
# -------------------------
|
# -------------------------
|
||||||
# Readiness checks (controller first, then VM fallback)
|
# Readiness checks (controller first, then VM fallback)
|
||||||
@@ -115,12 +122,11 @@
|
|||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Homarr | VM-side fetch (HTML via Python, with retries)
|
- name: Homarr | VM-side fetch (HTML via Python, with retries) # use SSHPASS env here too
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
- sshpass
|
- sshpass
|
||||||
- -p
|
- -e
|
||||||
- "{{ vm_pass }}"
|
|
||||||
- ssh
|
- ssh
|
||||||
- -o
|
- -o
|
||||||
- StrictHostKeyChecking=no
|
- StrictHostKeyChecking=no
|
||||||
@@ -139,13 +145,14 @@
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
PY
|
PY
|
||||||
|
environment:
|
||||||
|
SSHPASS: "{{ vm_pass }}"
|
||||||
register: homarr_vm
|
register: homarr_vm
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
when: homarr_controller.status | default(0) != 200 or homarr_controller.content is not defined
|
when: homarr_controller.status | default(0) != 200 or homarr_controller.content is not defined
|
||||||
retries: "{{ homarr_retries }}"
|
retries: "{{ homarr_retries }}"
|
||||||
delay: "{{ homarr_delay }}"
|
delay: "{{ homarr_delay }}"
|
||||||
# Wait until we actually got some HTML that likely belongs to Homarr
|
|
||||||
until: (homarr_vm.stdout | default('') | trim | length) > 0 and ('Homarr' in (homarr_vm.stdout | default('')))
|
until: (homarr_vm.stdout | default('') | trim | length) > 0 and ('Homarr' in (homarr_vm.stdout | default('')))
|
||||||
no_log: "{{ DEBUG == 0 }}"
|
no_log: "{{ DEBUG == 0 }}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user