Hi-Tech Institution Ph- 7092 90 91 92
Ansible components
Inventory
The “inventory” is a configuration file where you define the host information. In the above
/etc/ansible/hosts example, we declared two servers under test-hosts.
Playbooks
In most cases – especially in enterprise environments – you should use Ansible playbooks. A
playbook is where you define how to apply policies, declare configurations, orchestrate steps and
launch tasks either synchronously or asynchronously on your servers. Each playbook is composed of
one or more “plays”. Playbooks are normally maintained and managed in a version control system
like Git. They are expressed in YAML (Yet Another Markup Language).
Plays
Playbooks contain plays. Plays are essentially groups of tasks that are performed on defined hosts to
enforce your defined functions. Each play must specify a host or group of hosts. For example, using:
– hosts: all
…we specify all hosts. Note that YML files are very sensitive to white spaces, so be careful!
Tasks
Tasks are actions carried out by playbooks. One example of a task in an Apache playbook is:
- name: Install Apache httpd
A task definition can contain modules such as yum, git, service, and copy.
Roles
A role is the Ansible way of bundling automation content and making it reusable. Roles are
organizational components that can be assigned to a set of hosts to organize tasks. Therefore,
instead of creating a monolithic playbook, we can create multiple roles, with each role assigned to
complete a unit of work. For example: a webserver role can be defined to install Apache and Varnish
on a specified group of servers.
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
For getting the Modules details:
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
Working with modules:
1) Shell Module
2) YUM Module
3) Service Module
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
4) Copy Module:
Client:
Working with Playbook:
Playbook in YAML:
Eg:1:-
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
Eg:2:-
Interacting with AWS:
Installing boto3:
# yum install -y python python-dev python-pip
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
# pip install boto3
Playbook for Security group creation:
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
Output:
Playbook for Instance creation:
Hi-Tech Institution Ph- 7092 90 91 92
Hi-Tech Institution Ph- 7092 90 91 92
Reference Link : https://www.infinitypp.com/ansible/create-aws-resources-using-ansible/
Hi-Tech Institution Ph- 7092 90 91 92