Skip to content

Instantly share code, notes, and snippets.

@chrisdkemper
Created November 4, 2015 20:59
Show Gist options
  • Save chrisdkemper/7a9fff23309c7cf55963 to your computer and use it in GitHub Desktop.
Save chrisdkemper/7a9fff23309c7cf55963 to your computer and use it in GitHub Desktop.
A gist to represent a code sample
##vars.yml
#DigitalOcean stuff
digital_ocean_token: DIGITAL_OCEAN_TOKEN_HERE
digital_ocean_ssh_name: ocelot.pub
digital_ocean_ssh_pub: "{{ lookup('file', '/vagrant/ansible/ssh/ocelot.pub') }}"
digital_ocean_ssh_key: /vagrant/ansible/ssh/ocelot
digital_ocean_droplet_name: ocelotdroplet
digital_ocean_droplet_size_id: 512mb
digital_ocean_droplet_region_id: lon1
digital_ocean_droplet_image_id: 13089493
digital_ocean_droplet_private_networking: yes
#Neo4j stuff
neo4j_config_file: "{{ lookup('file', '/vagrant/ansible/neo4j/neo4j-server.properties') }}"
##neo4j.yml
---
- hosts: 127.0.0.1
connection: local
vars_files:
- vars.yml
tasks:
- name: Ensure ocelot key is available
digital_ocean:
state=present
command=ssh
name="ocelot.pub"
ssh_pub_key="{{ digital_ocean_ssh_pub }}"
api_token="{{ digital_ocean_token }}"
register: ssh_key
- name: Create a digital ocean droplet
digital_ocean:
state=present
command=droplet
name="{{ digital_ocean_droplet_name }}"
size_id="{{ digital_ocean_droplet_size_id }}"
region_id="{{ digital_ocean_droplet_region_id }}"
image_id="{{ digital_ocean_droplet_image_id }}"
wait_timeout=500
private_networking={{ digital_ocean_droplet_private_networking }}
ssh_key_ids={{ ssh_key.ssh_key.id }}
api_token="{{ digital_ocean_token }}"
unique_name=yes
register: my_droplet
- name: Register droplet as dynamic host
add_host:
name="{{ digital_ocean_droplet_name }}"
groups=droplets
ansible_ssh_host="{{ my_droplet.droplet.networks.v4[1].ip_address }}"
ansible_ssh_user=root
ansible_ssh_private_key_file="{{ digital_ocean_ssh_key }}"
- hosts: droplets
tasks:
- debug: msg="{{ ansible_eth0.ipv4.address }}"
- debug: msg="{{ ansible_eth1.ipv4.address }}"
- name: Check if neo4j is installed
command: dpkg --get-selections | grep neo4j
register: neo4j_check
- name: Key1
shell: wget -O - http://debian.neo4j.org/neotechnology.gpg.key | apt-key add -
when: neo4j_check.stdout == ""
- name: Key2
shell: echo 'deb http://debian.neo4j.org/repo stable/' > /etc/apt/sources.list.d/neo4j.list
when: neo4j_check.stdout == ""
- name: Install Neo4j
apt: name=neo4j update_cache=yes state=latest
when: neo4j_check.stdout == ""
- name: Set the correct address
lineinfile: dest=/etc/neo4j/neo4j-server.properties
regexp=^#org.neo4j.server.webserver.address=
line=org.neo4j.server.webserver.address={{ ansible_eth1.ipv4.address }} #Internal IP of the droplet
when: neo4j_check.stdout == ""
notify:
- restart neo4j
handlers:
- name: restart neo4j
service: name=neo4j-service state=restarted
- name: restart machine
command: shutdown -r now "Ansible updates triggered"
async: 0
poll: 0
ignore_errors: true
- name: waiting for server to come back
local_action: wait_for host={{ inventory_hostname }}
state=started
sudo: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment