Skip to content

Instantly share code, notes, and snippets.

@rahman541
Last active November 4, 2017 15:13
Show Gist options
  • Save rahman541/50a640db7d7bcd43fdda988afe5b9710 to your computer and use it in GitHub Desktop.
Save rahman541/50a640db7d7bcd43fdda988afe5b9710 to your computer and use it in GitHub Desktop.
Ansible: Automate IT Infrastructure configuration & deployment.

Intro

This will install & running nginx latest on Ubuntu with ip 192.168.48.133. Tested on Ubuntu 16.04 x64 LTS

Setup

Install Ansible

Install on OS running Ubuntu or in VM will work also.

sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

Refer to official docs here

Add inventory / host

This will contain ip to where you want to deploy. Make sure ssh key already added on that host. Refer this on how to add ssh key. Edit file /etc/ansible/hosts fill the following:

# Application Server
[webserver]
192.168.48.133

Create a new playbook

Create new file play.yml with content:

---
- hosts: webserver
  become: yes
  become_method: sudo
  tasks:
  - name: install nginx
    apt : pkg=nginx state=installed update_cache=true
    notify:
        - start nginx
  handlers:
  - name: start nginx
    service: name=nginx state=started

Run ansible playbook:

ansible-playbook --ask-become-pass play.yml

To test if nginx is running:

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