title | category | layout | description |
---|---|---|---|
Ansible quickstart |
Ansible |
2017/sheet |
A quick guide to getting started with your first Ansible playbook.
|
$ brew install ansible # OSX
$ [sudo] apt install ansible # elsewhere
Ansible is available as a package in most OS's.
See: Installation
~$ mkdir setup
~$ cd setup
Make a folder for your Ansible files.
See: Getting started
[sites]
127.0.0.1
192.168.0.1
192.168.0.2
192.168.0.3
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
- 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
- name: do something in the shell
shell: echo hello > /tmp/abc.txt
- name: install bundler
gem: name=bundler state=latest
See: Intro to Playbooks
~/setup$ ls
hosts
playbook.yml
~/setup$ ansible-playbook -i hosts playbook.yml
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [127.0.0.1]
TASK: [install nginx] *********************************************************
ok: [127.0.0.1]
TASK: start nginx every bootup] ***********************************************
ok: [127.0.0.1]
...
- Getting started with Ansible (lowendbox.com)
- Getting started (docs.ansible.com)
- Intro to Inventory (docs.ansible.com)
- Intro to Playbooks (docs.ansible.com)
- Ansible Tutorial for Beginners: Playbook & Examples (spacelift.io)
- Working with Ansible Playbooks – Tips & Tricks with Examples (spacelift.io)