marc:linux:chatgtp
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| marc:linux:chatgtp [2023/02/10 10:06] – marcv | marc: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 ==== | ||
| + | |||
| + | < | ||
| + | --- | ||
| + | - 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 == " | ||
| + | | ||
| + | - name: Update package index | ||
| + | yum: | ||
| + | name: " | ||
| + | state: latest | ||
| + | when: ansible_os_family == " | ||
| + | |||
| + | - name: Install patches | ||
| + | apt: upgrade=dist | ||
| + | when: ansible_os_family == " | ||
| + | |||
| + | - name: Install patches | ||
| + | yum: name=* state=latest | ||
| + | when: ansible_os_family == " | ||
| + | |||
| + | - name: Check if a reboot is required | ||
| + | shell: "ls / | ||
| + | register: reboot_required | ||
| + | changed_when: | ||
| + | |||
| + | - name: Perform reboot | ||
| + | reboot: | ||
| + | when: reboot_required.rc == 0 | ||
| + | </ | ||
| + | |||
| + | 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 / | ||
marc/linux/chatgtp.1676020012.txt.gz · Last modified: (external edit)
