Changing permission of a file

Changing ownership of a file

Managing Packages

So, we can manage the packages installed on all the hosts connected to ansible by using ‘yum’ & ‘apt’ modules & the complete commands used are

Check if package is installed & update it

$ ansible <group> -m yum -a “name=ntp state=latest”

Check if package is installed & don’t update it

$ ansible <group> -m yum -a “name=ntp state=present”

Check if package is at a specific version

$ ansible <group> -m yum -a “name= ntp-1.8 state=present”

Check if package is not installed

$ ansible <group> -m yum -a “name=ntp state=absent”

Managing services

So to manage services with ansible, we use a modules ‘service’ & complete commands that are used are,

Starting a service

$ ansible <group> -m service -a “name=httpd state=started”

Stopping a service

$ ansible <group> -m service -a “name=httpd state=stopped”

Restarting a service

$ ansible <group> -m service -a “name=httpd state=restarted”

So this completes our tutorial of some one line, simple ansible commands that can be used with ansible. Also, for our future tutorials, we will learn to create plays & playbooks that help us manage our hosts more easliy & efficiently.

If you think we have helped you or just want to support us, please consider these :-