- setup ansible playbook from ppa for latest available update
- create sample local playbook <E.g. whoami>
- execute playbook to remote server
just a simple command
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install -y ansible
at least, the current stable version is 1.9.x to check the latest version from github repository, and check ansible is ready from command
ansible-playbook --version
we have to create a simple playbook
echo '
---
- hosts: all
tasks:
- name: Hello
shell: echo "Hello world"
' > /tmp/playbook.yml
and execute the playbook with command
ansible-playbook -i "localhost," -c local /tmp/playbook.yml -v
so the output you could see like this
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [Hello] *****************************************************************
changed: [localhost] => {"changed": true, "cmd": "echo \"Hello world\"", "delta": "0:00:00.001152", "end": "2015-10-26 18:14:33.107658", "rc": 0, "start": "2015-10-26 18:14:33.106506", "stderr": "", "stdout": "Hello world", "warnings": []}
PLAY RECAP ********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
we can use these command to execute playbook on remote server
ansible-playbook -k -u srandev -i "192.168.1.150," -c ssh ./playbook.yml -v
and the output
SSH password:
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [192.168.1.150]
TASK: [Hello] *****************************************************************
changed: [192.168.1.150] => {"changed": true, "cmd": "echo \"Hello world\"", "delta": "0:00:00.005768", "end": "2015-10-26 18:28:03.531380", "rc": 0, "start": "2015-10-26 18:28:03.525612", "stderr": "", "stdout": "Hello world", "warnings": []}
PLAY RECAP ********************************************************************
192.168.1.150 : ok=2 changed=1 unreachable=0 failed=0
- the option -k we use for asking ssh password
- the option -u for the remote ssh user, E.g. srandev