Wednesday, August 21, 2019

Copy,Fetch,Apt,Yum,Service,Setup modules

Copy Module:
  • Copies a file from local-box to remote system
  • Has "backup" capability
  • Can do validation remotely
Fetch Module:
  • Opposite to Copy module, Pulls a file from remote host to local system
  • Can use md5 check-sums to validate
Apt module:
  • Manages installed applications on Debian based systems
  • Can install, update, or delete packages
  • Can update entire system

 Yum module:
  • Manages installed applications on Redhat-based systems
  • Can install, update, or delete packages
  • Can update entire system
Service Module:
  • Can stop, start or restart services
  • Can enable services to start on boot 

Setup Module:
  • Gather facts on remote systems
  • Used in Playbooks

Demo of above modules:

  1. Install web server (Yum module)
  2. Start Web server (service module)
  3. Install DB Server (Yum module)
  4. Start DB Server (Service module)
  5. Stop Firewalls (Service module)

 ansible-doc -l --> To list all modules.

Select the module you want and see the full description of it.
ansible-doc yum

To install apache:

ansible webservers -i inventory -m yum -a "name=httpd state=present" --sudo

It will check already installed or not and skip if already there.It can be seen using the changed part in the output.


ansible webservers -i inventory -m yum -a "name=httpd enabled=yes state=started" --sudo

This will start also the service.

 ansible dbservers -i inventory -m yum -a "name=mysql-server state=present" --sudo
 ansible dbservers -i inventory -m yum -a "name=mysql-server state=started" --sudo


 To stop firewall:
  ansible webservers:dbservers -i inventory -m service -a "name=iptables state=stopped" --sudo


ansible web1 -i inventory -m setup

Will give details/facts about the system(as key/value pairs in json structure), we can use these values as the variables.


ansible web1 -i inventory -m setup -a "filter=ansible_eth*"
ansible web1 -i inventory -m setup -a "filter=ansible_mounts"
ansible all -i inventory -m setup --tree ./setup  --> to dump all data in the setup folder.




No comments:

Post a Comment