Ansible tutorial

Ansile is an automation and orchestration tool. It is software that automates software provisioning, configuration management, and application deployment. The best way to increase my DevOps skill.

Start your Project

$ mkdir project
$ cd project

Create Ansible Inventory file

~/project/hosts

[webserver]
127.0.0.1
192.168.0.1

List of hosts you want to manage, grouped into groups.(127.0.0.1 deploy your local machine)

Create ansible playbook

~/project/playbook.yml

- hosts: 127.0.0.1
user: root
tasks:
  - name: install nginx
    apt: pkg=nginx state=present
  - name: start nginx every bootup
    service: name=nginx state=started enabled=yes

Ansible run playbook

ansible-playbook -i hosts playbook.yml

Structure ansible role

roles/
common/
tasks/
handlers/
files/ # 'copy' will refer to this
templates/ # 'template' will refer to this
meta/ # Role dependencies here
vars/
defaults/
main.yml

Ansible Modules

Service modules

- service:
   name: nginx
   state: started
   enabled: yes

Install Nginx modules

tasks:
  - name: ensure nginx is at the latest version
    apt: name=nginx state=latest
  - name: start nginx
    service:
     name: nginx
     state: started

Ansible shell

- shell: apt-get install nginx -y

script module

- script: /home/huupv/script.sh
  args:
    creates: /path/file # skip if this exists
    removes: /path/file # skip if this is missing
    chdir: /path # cd here before running

Keep reading. I will update later!