Ansible Notes
Ansible Notes
it is an open source engine automated the application depoly, it has GUI called
ansible tower dependence is python
we use ansible bcoz to configure and manage the setup in all the servers at
time that why use the automation tool ansible
with help of master - slave concepts we install the diff tools in diff server with
ip address using ansible automation tool
Chef is too long we have write cook book and upload in chef and perform in
ther slave servers compare ansible is too light we use
vi /etc/ansible/hosts add [dev] private ip addresses [test]ip address check with
command ansible all --lists-hosts
host pattern ansible groupname [1, 4] --lists-hosts
Playbook Playbooks in ansible are written in YAML language.
It is a human readable & serialization language commonly used for
configuration files. You can write codes consisting of vars, tasks, handlers, files,
templates and roles.
Each playbook is composed of one or more modules in a list.
Module is a collection of configuration files.
Playbooks are mainly divided into sections like
TARGET SECTION: Defines host against which playbooks task has to be
executed. VARIABLE SECTION: Defines variables.
TASK SECTION: List of all modules that we need to run in an order.
- hosts:ops or dev
user: ansible
become:yes
connection: ssh
tasks:
- name: installing tree in the hosts or nodes or in slave servers
action: yum name=tree state=present
set_fact: abc=httpd pass variables in second file this file is passed in first
file(include: two. Yml
ansible-vault encrypt five.yml
ansible-vault decrypt five.yml
ansible-vault rekey five.yml
RAW COMMANDS
These are used to when noramlly commands are not working for forcefully we use
thes raw
=>- name: raw commands
raw: yum -y install vim-common
SETUP MODULES
These are pre-defined module for debugging purpose
=>ansible -m setup -a "filter=ansible_os_family" privIPAddress
=>ansible -m setup -a "filter=ansible_kernel" IPaddress
=>ansible -m setup -a "filter=ansible_devices" ipaddress
=>ansible -m setup -a "filter=ansible_default_ipv4" ipaddress
=>ansible -m setup -a "filter=ansible_processor_cores" ipaddress
=>ansible -m setup -a "filter=ansible_architecture" ipaddress
DEBUGGING
Ansible offers a task debugger so you can fix errors during execution instead of
editing your playbook and running it again to see if your change worked.
After performing any task we get data in JSON format we can store it msg in the
debug module and we can print
=>tasks:
- name: get group list
command: cat/etc/group
register: one
- debug:
msg: "the list group {{one.stdout}}