Site Tools


marc:linux:chatgtp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
marc:linux:chatgtp [2023/02/10 10:06] marcvmarc:linux:chatgtp [2023/02/10 10:10] (current) marcv
Line 21: Line 21:
  
 This however only shows last ip address This however only shows last ip address
 +
 +==== Patch Red Hat and Debian based systems and perform reboot if required using an ansible playbook ====
 +
 +<code>
 +---
 +- name: Patch both Debian and Red Hat based systems
 +  hosts: all
 +  become: yes
 +
 +  tasks:
 +    - name: Update package index
 +      apt: update_cache=yes
 +      when: ansible_os_family == "Debian"
 +      
 +    - name: Update package index
 +      yum: 
 +        name: "*"
 +        state: latest
 +      when: ansible_os_family == "RedHat"
 +
 +    - name: Install patches
 +      apt: upgrade=dist
 +      when: ansible_os_family == "Debian"
 +
 +    - name: Install patches
 +      yum: name=* state=latest
 +      when: ansible_os_family == "RedHat"
 +
 +    - name: Check if a reboot is required
 +      shell: "ls /var/run/reboot-required"
 +      register: reboot_required
 +      changed_when: false
 +
 +    - name: Perform reboot
 +      reboot:
 +      when: reboot_required.rc == 0
 +</code>
 +
 +In this playbook, the apt module is used to update the package index and install patches on Debian-based systems, while the yum module is used for the same on Red Hat-based systems. The when statement is used to conditionally execute the correct module based on the value of ansible_os_family.
 +
 +After the patches have been installed, the playbook checks if a reboot is required by running the ls /var/run/reboot-required command. If the command returns a zero exit code, indicating that a reboot is required, the reboot module is used to perform the reboot.
marc/linux/chatgtp.1676020012.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki