How to run:
If single host give host ip like below in the command else for group
patch, update the /etc/ansible/hosts file with server list and give the group
name as host variable value. The playbook also collects required information like mount status resolv.conf and ntpstat as per my requirement, you can add your commands in the shell section. The information collected will be stored in the name of serverip-prepatch.txt and serverip-postpatch.txt and saves it in the playbook directory.
# ansible-playbook patchreboot.yml
--extra-vars "host=10.10.11.70" --user ranjith
- hosts: "{{ host }}"
become: yes
become_method: sudo
tasks:
- name: running prepatch info commands
shell: |
df -hP
cat /etc/resolv.conf
ntpstat
register: prepatch
ignore_errors: True
- name: removing old prepatch info file
local_action: file path={{ playbook_dir }}/{{ inventory_hostname }}-prepatch.txt state=absent
- name: storing prepatch info
local_action: copy content={{ prepatch.stdout }} dest={{ playbook_dir }}/{{ inventory_hostname }}-prepatch.txt
- name: upgrade all packages
yum:
name: '*'
state: latest
- name: restart server
command: /sbin/reboot
async: 0
poll: 0
ignore_errors: true
- name: Pause for 180 seconds
pause: minutes=3
- name: wait for the server to restart
local_action: wait_for host={{ inventory_hostname }}
port=22
delay=15
timeout=300
state=started
connect_timeout=15
- name: restarting ntpserver
service:
name: ntpd
state: restarted
enabled: yes
- name: running postpatch info commands
shell: |
df -hP
cat /etc/resolv.conf
sleep 10
ntpstat
register: postpatch
ignore_errors: True
- name: removing old postpatch info file
local_action: file path={{ playbook_dir }}/{{ inventory_hostname }}-postpatch.txt state=absent
- name: storing postpatch info
local_action: copy content={{ postpatch.stdout }} dest={{ playbook_dir }}/{{ inventory_hostname }}-postpatch.txt
nice post.Keep updating Devops Online Course
ReplyDeleteThank you for sharing best infromation.
ReplyDeleteFull Stack Training in Chennai | Certification | Online Training Course| Full Stack Training in Bangalore | Certification | Online Training Course | Full Stack Training in Hyderabad | Certification | Online Training Course | Full Stack Developer Training in Chennai | Mean Stack Developer Training in Chennai | Full Stack Training | Certification | Full Stack Online Training Course
I just loved your article.I am Here to Get Learn Good Stuff About DevOps, Thanks For Sharing
ReplyDeleteThis is most informative and also this post most user friendly
DevOps Training in Chennai
DevOps Online Training in Chennai
DevOps Training in Bangalore
DevOps Training in Hyderabad
DevOps Training in Coimbatore
DevOps Training
DevOps Online Training
Linux Stuffs: Ansible Playbook To Patch And Reboot Rhel 6 And Rhel 7 Servers >>>>> Download Now
ReplyDelete>>>>> Download Full
Linux Stuffs: Ansible Playbook To Patch And Reboot Rhel 6 And Rhel 7 Servers >>>>> Download LINK
>>>>> Download Now
Linux Stuffs: Ansible Playbook To Patch And Reboot Rhel 6 And Rhel 7 Servers >>>>> Download Full
>>>>> Download LINK
Great blog.
ReplyDeleteLinux classes in Pune