Skip to content

Instantly share code, notes, and snippets.

@AaronSeibert
Last active March 20, 2018 15:12
Show Gist options
  • Save AaronSeibert/3c3728299b9b71625523a24ebbd2a758 to your computer and use it in GitHub Desktop.
Save AaronSeibert/3c3728299b9b71625523a24ebbd2a758 to your computer and use it in GitHub Desktop.
[0] % tree
.
├── ansible.cfg
├── production
│   ├── group_vars
│   │   ├── nyc1
│   │   └── webservers
│   └── hosts
├── shared_hosting.retry
└── shared_hosting.yml
[playbook]
---
- name: Bootstrap DigitalOcean provider
hosts: localhost
connection: local
tasks:
- name: ensure ssh key exists
user: >
name={{ ansible_user_id }}
generate_ssh_key=yes
ssh_key_file=.ssh/id_rsa
- name: ensure key exists at DigitalOcean
digital_ocean: >
state=present
command=ssh
name=my_ssh_key
ssh_pub_key={{ lookup('file', '~/.ssh/id_rsa.pub') }}
register: my_ssh_key
- name: ensure droplets exist
digital_ocean: >
state=present
command=droplet
name={{ item }}
unique_name=yes
size_id={{ hostvars[item]['size'] }}
region_id={{ hostvars[item]['region'] }}
image_id={{ hostvars[item]['image'] }}
ssh_key_ids={{ my_ssh_key.ssh_key.id }}
register:
with_items: "{{ groups['servers'] }}"
[ansible.cfg]
[defaults]
inventory = production
[group_vars/nyc1]
---
region: nyc1
[group_vars/webservers]
---
size: 1gb
image: ubuntu-17-10-x64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment