Ansible script examples

EXAMPLE: Restart NTP daemon in Linux

First create the playbook pbntprestart.yml as below and run using this command. The cdhservers is where you define all your hostnames.

$ ansible-playbook pbntprestart.yml -u root -k

The content of pbntprestart.yml  is below:

$ cat pbntprestart.yml

– hosts: cdhservers
tasks:

– name: NTPRESTART
shell: service ntpd restart
register: out1
– debug: var=out1.stdout_lines

– name: NTPSTATUS
shell: ntpstat
register: out2
– debug: var=out2.stdout_lines

– name: NTPDSTATUS
shell: service ntpd status
register: out3
– debug: var=out3.stdout_lines

 

EXAMPLE: Run step by step each ansible task

ansible-playbook pbtest.yml -u userid -k –step

 

EXAMPLE: Check linux system basic status

$ cat pbchkuptime.yml

– hosts: cdhservers
tasks:
– name: CHECKUPTIME
shell: uname -a;uptime;free -h;df -h
register: out1
– debug: var=out1.stdout_lines

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s