Last active
January 2, 2020 19:41
-
-
Save davidlares/a6459a6d678080bb8e5856113633151f to your computer and use it in GitHub Desktop.
Digital Ocean's basic droplet setup with Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[server] | |
Here goes your Droplet IP | |
[server:vars] | |
ansible_user=root | |
ansible_ssh_private_key_file=~/.ssh/id_rsa.pub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: server | |
remote_user: root | |
vars: | |
user: david | |
packages: ['curl','git','ufw','nano'] | |
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}" | |
tasks: | |
- name: Create a new user | |
user: | |
name: {{ user }} | |
state: present | |
groups: sudo | |
append: true | |
create_home: true | |
shell: /bin/bash | |
- name: Add SSH key | |
authorized_key: | |
user: "{{ user }}" | |
state: present | |
key: {{ key }} | |
- name: Update packages | |
apt: update_cache=yes | |
- name: Install packages | |
apt: name={{ packages }} state=latest | |
- name: UFW SSH | |
ufw: | |
rule: allow | |
name: OpenSSH | |
- name: UFW Deny | |
ufw: | |
state: enabled | |
policy: deny |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before using this, you will have to: