Ansible Guide Cheat Sheet

From WikiOD

Here is the cheatsheat of Ansible Guide and basic guide on how to use Ansible Guide

Install Ansible[edit | edit source]

$ brew install ansible            # OSX
$ [sudo] apt install ansible      # elsewhere

Ansible is available as a package in most OS’s.

See: Installation

Start your project[edit | edit source]

~$ mkdir setup
~$ cd setup

Make a folder for your Ansible files.

See: Getting started

Creating your files[edit | edit source]

Inventory file[edit | edit source]

~/setup/hosts[edit | edit source]


This is a list of hosts you want to manage, grouped into groups. (Hint: try using localhost ansible_connection=local to deploy to your local machine.)

See: Intro to Inventory

Playbook[edit | edit source]

~/setup/playbook.yml[edit | edit source]

- hosts:
  user: root
    - name: install nginx
      apt: pkg=nginx state=present

    - name: start nginx every bootup
      service: name=nginx state=started enabled=yes

    - name: do something in the shell
      shell: echo hello > /tmp/abc.txt

    - name: install bundler
      gem: name=bundler state=latest

See: Intro to Playbooks

Running[edit | edit source]

Running ansible-playbook[edit | edit source]

~/setup$ ls

Running the playbook[edit | edit source]

~/setup$ ansible-playbook -i hosts playbook.yml
PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
ok: []

TASK: [install nginx] *********************************************************
ok: []

TASK: start nginx every bootup] ***********************************************
ok: []

Read more[edit | edit source]