0% found this document useful (0 votes)
223 views5 pages

Ansible Notes

Ansible is an open source tool for automating application deployment and configuration management. It allows users to configure, manage, and deploy applications and infrastructure across multiple machines. Ansible works by pushing out small programs called modules to systems over SSH and capturing the output. Playbooks in Ansible define workflows in YAML format and allow automating complex multi-step tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
223 views5 pages

Ansible Notes

Ansible is an open source tool for automating application deployment and configuration management. It allows users to configure, manage, and deploy applications and infrastructure across multiple machines. Ansible works by pushing out small programs called modules to systems over SSH and capturing the output. Playbooks in Ansible define workflows in YAML format and allow automating complex multi-step tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ANSIBLE NOTES

Ansible is configuration (ram, OS , storage, ip address), management (update,


delete, add) tool

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

Ansible Setup 1) amazon-linux-extras install ansible2 -y, yum install python


python-pip python-level openssl -y, user add ansible, password for user,visudo,
password authentication, restart sshd

same actions in slaves except ansible and python installation

Connect slave to master in master generate ssh-keygenerate and ssh-copy-id


@private io bocz private ip will not change when restart

Slaves adds as groups in master root user  vi/etc/ansible/ansible.cfg in that file


uncomment the inventory and sudo lines

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.

Sample playbook starts with --- and ends  ...

- 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

to run the playbook ansible-playbook name


----
      -host:which server
      become:yes
      user: ansible
      connection: ssh
          vars:
           -abc:git
            -xyz:tree
           tasks:
                -inculde: two.yml
                - name: installing git
                 -action: yum name={{abc)state=present              - name: installing tree
-action yum name=((xyz)} state-present
in the second yaml filke
----
-set_fact: abc-maven
name: installing maven
action:yum name-((abc)) state-present
ansible-playbook --skips-tags "abc"

ansible-playbook one.yml --extra-vars "ABC=maven xyz=git"

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

MODULES USED IN YAML FILE


=>name(task matter for reference)
=>state(present,absent,restart
=>include(two.yml)
=>set_fact(abc=maven)
=>handlers(
=>notify(
=>action(yum name=httpd state=present)
=>command(yum install maven
=>when(condition purpose)
=>user(name: username,state: present)
=>group(name :gname,state: present)
=>copy(dest,content)
=>file(path: devops.txt,state: touch)
=>file(path,state,chmod: 777)
=>folder(file,path,state: directory)
=>files(path: "{{items}}",state: touch,with_items: -file1,file2)
=>copy(dest: /var/www/html/index.html content : | <h1>hello</h1>)
=>yum(name,state)
=>service(name,state=restarted)
=>git:
repo: "repo link"
dest: "/home/mycode"
=>LOOPS

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}}

SETUP Ansible Roles using PLAYBOOK


SETUP Jenkins using PLAYBOOK
SETUP HTTPD using PLAYBOOK

You might also like