Setup Digital Ocean Droplet to Run Ansible With UserData

in digitalocean •  8 years ago 

Digital Ocean Ansible Setup UserData



Digital Ocean

For more information on Digital Ocean, visit digitalocean.com


Description:


This is a informational tutorial on how to launch Digital Ocean Droplets setup to run Ansible playbooks using userdata. When launching a droplet via the Digital Ocean console or the API, a user has the option of specifying optional userdata. The userdata section is a set of instructions in bash script format that allow the user to customize the droplet on launch by auto executing any instructions or commands in the userdata section of the droplet configuration. This informational tutorial contains a userdata script for multiple platforms on how to get a droplet launched, and ready to run playbooks on launch.


Pre-Requisites:


1.    OS:


COMPATIBILITY:

  CentOS 6 and 7

  Debian 8 Jessie

  Ubuntu 14.04 Trusty and up


2.    Digital Ocean Account:

In order to test out the userdata scripts, you must already have a digital ocean account provisioned. When logged into the account, simply create a new droplet the way you normally would, with the additional step of selecting the User data option under the Select additional options section of the droplet launch window. This will open a text box that will allow you to paste in a userdata script that will be fired off on the droplet once the droplet has launched.


UserData Scripts:


  CentOS 6:


#!/bin/bash

# Install Epel, as it holds the latest Ansible RPM, then update
yum install epel-release -y
rpm --import http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
yum update -y

# Install PIP
curl "https://bootstrap.pypa.io/get-pip.py" -o "/tmp/get-pip.py"
python /tmp/get-pip.py
pip install pip --upgrade
rm -fr /tmp/get-pip.py

# Install Ansible
yum install git ansible -y
mkdir -p /etc/ansible/roles || exit 0
echo `hostname` ansible_connection=local > /etc/ansible/hosts


  CentOS 7:


#!/bin/bash

# Install Epel, as it holds the latest Ansible RPM, then update
yum install epel-release -y
rpm --import http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
yum update -y

# Install PIP
curl "https://bootstrap.pypa.io/get-pip.py" -o "/tmp/get-pip.py"
python /tmp/get-pip.py
pip install pip --upgrade
rm -fr /tmp/get-pip.py

# Install Ansible
yum install git ansible -y
mkdir -p /etc/ansible/roles || exit 0
echo `hostname` ansible_connection=local > /etc/ansible/hosts

yum install git ansible -y
mkdir -p /etc/ansible/roles || exit 0
echo `hostname` ansible_connection=local > /etc/ansible/hosts


  Debian 8
  Ubuntu Trusty and Up:


#!/bin/bash

# Update and install Git:
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y git

# If using Ubuntu, install some required python packages:
sudo apt-get install -y python-dev python-openssl libffi-dev libssl-dev gcc

# Use Pip to install ansible:
sudo easy_install pip
sudo pip install pip --upgrade
sudo pip install ansible
sudo mkdir -p /etc/ansible/roles || exit 0
sudo echo `hostname` ansible_connection=local > /etc/ansible/hosts


Post Requisites:


None


References:


Clusterfrak

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @rnason! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of posts published

Click on any badge to view your own Board of Honnor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
http://clusterfrak.com/devops/ansible/digital_ocean_userdata/

I, have no idea what this means. laymans terms please

Ansible is a configuration management utility that lets you easily set up a process for systematically installing an application on a variety of different servers. This tutorial just walks through taking an ansible playbook (or set of instructions on how to install nginx) and running it on a server to install nginx without having to go through the process manually. Download the role, execute the role, and nginx is installed and running on the server. :)

Great article