Portál AbcLinuxu, 27. října 2025 19:11
---
- name: run the playbook tasks on the hosts
hosts: all
tasks:
- name: print out the hostname of target
command: hostname
- name: ensure aptitude is installed
command: apt -y install aptitude
- name: update the apt package index i.e. apt update
apt: update_cache=yes
- name: upgrade system packages i.e. apt upgrade
apt: upgrade=yes
reboot, který počká, až restart doběhne a selže.
Debianu nemaje, na druhou půlku bohužel odpovědět nemůžu.
serial: 1tak a by se servery zpracovavali jeden po druhem. Zadruhe bych pouzil direktivu:
any_errors_fatal: truektera zajisti, ze se pri selhani jedineho hosta cely proces zastavi.
---
- name: run the playbook tasks on the hosts
hosts: all
serial: 1
any_errors_fatal: true
tasks:
- name: Print out the hostname of target
command: hostname
- name: Ensure aptitude and reboot-notifier are installed
command: apt -y install aptitude python-apt reboot-notifier
- name: Update the apt package index (apt update)
apt: update_cache=yes
- name: Upgrade system packages (apt upgrade)
apt: upgrade=yes
- name: List installed and updated packages
shell: grep -E "^$(date +%Y-%m-%d).+ (install|upgrade) " /var/log/dpkg.log |cut -d " " -f 3-5
register: result
- name: Show Output
debug: msg="{{ result.stdout_lines }}"
- name: "Reboot server if kernel/libs updated and requested by the system"
shell: sleep 2 && shutdown -r now 'Rebooting server to update system libs/kernel as needed' removes=/var/run/reboot-required
become: true
async: 1
poll: 0
ignore_errors: true
- name: "Wait for system to become reachable again"
local_action: wait_for host={{ ansible_default_ipv4.address }} port=22 delay=10 state=started
become: false
--- ansible_user: root ansible_connection: ssh ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q root@gw01.domain.com"'Tohle bohužel v tomto případě nefunguje
- name: "Reboot server if kernel/libs updated and requested by the system"
shell: sleep 2 && shutdown -r now 'Rebooting server to update system libs/kernel as needed' removes=/var/run/reboot-required
become: true
async: 1
poll: 0
ignore_errors: true
- name: "Wait for system to become reachable again"
local_action: wait_for host={{ ansible_default_ipv4.address }} port=22 delay=10 state=started
become: false
Nějaký nápad, jak to dělat / řešit ?ProxyCommand ssh -q muj_proxy_server nc -q0 muj_koncovy_server:12322nebo třeba
ProxyJump root@muj_proxy_server:22
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.