Skip to content

Ansible Getting Started

Alexandru Zbarcea edited this page Feb 28, 2015 · 1 revision

Install:

yaourt python-pip ansible
export WK_DIR=~/projects/ansible-getting-started
mkdir $WK_DIR
cd $WK_DIR

Let's manage some hosts:

$ vi hosts
[sites]
127.0.0.1
192.168.0.1
192.168.0.2
192.168.0.3

Create first Playbook

# ~/setup/playbook.yml

- hosts: 127.0.0.1
  user: root
  tasks:
    - name: git
      pacman: pkg=git state=present

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

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

Run it

$ ls
hosts
playbook.yml
$ ansible-playbook -i hosts playbook.yml

PLAY [127.0.0.1] ************************************************************** 

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

TASK: [git] ******************************************************************* 
ok: [127.0.0.1]

TASK: [start docker every bootup] ********************************************* 
ok: [127.0.0.1]

TASK: [do something in the shell] ********************************************* 
changed: [127.0.0.1]

PLAY RECAP ******************************************************************** 
127.0.0.1                  : ok=4    changed=1    unreachable=0    failed=0   

Read more