Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Getting started with Ansible

Get started with Ansible in 2 minutes

Install Ansible

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

Start your project

~$ mkdir setup
~$ cd setup

Create an inventory file

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

# ~/setup/hosts


Create your first Playbook

# ~/setup/playbook.yml

- 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

Run it

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

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

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

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

Read more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment