-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.yaml
169 lines (168 loc) · 5 KB
/
main.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
- name: Create Droplet in Digital Ocean
hosts: localhost
connection: local
gather_facts: no
tasks:
- include_vars:
file: vars
# - name: Query one tag
# digital_ocean_tag_facts:
# oauth_token: '{{do_api_token}}'
# tag_name: development
# register: one_tag
- set_fact:
# dev_droplet_id: '{{one_tag.data.resources.droplets.last_tagged.id}}'
droplet_exists: yes
# when: one_tag.data.resources.count == 1
- include_role:
name: droplet
- include_role:
name: route53
when: droplet_ip is defined
- add_host:
name: "{{fqdn}}"
groups: do
changed_when: False
when: fqdn is defined
- name: Provision development droplet
hosts: do
remote_user: root
gather_facts: False
vars:
ansible_ssh_private_key_file: "{{lookup('file', ssh_key_path)}}"
pre_tasks:
- name: Wait for port 22 to become available
local_action: "wait_for port=22 host={{inventory_hostname}}"
- name: 'Install Python'
raw: apt-get -y install python
tasks:
- include_vars:
file: vars
- name: Create user
user:
name: "{{username}}"
shell: /bin/bash
createhome: yes
register: create_user
- name: Create .ssh directory
file:
path: "~{{username}}/.ssh"
state: directory
owner: "{{username}}"
group: "{{username}}"
mode: 0700
when: create_user.changed == True
- name: Upload SSH key
copy:
src: "{{ssh_key_path}}"
dest: "~{{username}}/.ssh"
owner: "{{username}}"
group: "{{username}}"
mode: 0700
when: create_user.changed == True
- name: Upload SSH public key
copy:
src: "{{public_key_file}}"
dest: "~{{username}}/.ssh"
owner: "{{username}}"
group: "{{username}}"
mode: 0700
become_user: '{{username}}'
when: create_user.changed == True
- name: Create authorized key file
authorized_key:
user: kbreit
state: present
key: "{{lookup('file', public_key_file)}}"
become_user: '{{username}}'
when: create_user.changed == True
- name: Create wheel group for sudo
group:
name: wheel
state: present
when: create_user.changed == True
- name: Allow 'wheel' group to have passwordless sudo
lineinfile:
dest: /etc/sudoers
state: present
regexp: "^%wheel"
line: '%wheel ALL=(ALL) NOPASSWD: ALL'
validate: 'visudo -cf %s'
when: create_user.changed == True
- name: Add user to wheel group
user:
name: '{{username}}'
groups: wheel
append: yes
state: present
when: create_user.changed == True
- name: Install apt Python libraries
command: apt-get -y install python-apt python3-apt
- name: Install programs
apt:
state: present
name: "{{packages}}"
vars:
packages:
- tmux
- git
- vim
- make
- build-essential
- libssl-dev
- zlib1g-dev
- libbz2-dev
- libreadline-dev
- libsqlite3-dev
- wget
- curl
- libncurses5-dev
- libncursesw5-dev
- xz-utils
- libffi-dev
- liblzma-dev
- ansible
- name: Provision development environment as user
hosts: do
remote_user: '{{username}}'
gather_facts: False
vars_files:
- vars
vars:
ansible_ssh_private_key_file: "{{lookup('file', ssh_key_path)}}"
tasks:
- name: Start ssh-agent
shell: |
eval `ssh-agent -s`
ssh-add
exit 0
- name: Create directory
file:
path: ~/projects
state: directory
- name: Clone git repositories
git:
dest: "~{{username}}/projects/{{item.name}}"
repo: "{{item.repo}}"
accept_hostkey: yes
key_file: "~/.ssh/{{private_key_name}}"
loop:
- {name: 'ansible-playbook', repo: '[email protected]:kbreit/ansible-playbooks.git'}
- {name: 'ansible', repo: '[email protected]:kbreit/ansible.git'}
- {name: 'cloud_dev_environment', repo: '[email protected]:kbreit/cloud_dev_environment.git'}
register: git_clone
- name: Add git remote for Ansible
command: git -C ~/projects/ansible/ remote add upstream [email protected]:ansible/ansible.git
when: git_clone.changed == True
- name: Install pyenv
shell: curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
- name: Add pyenv information to .bashrc
lineinfile: # This could be changed to blockinfile
dest: ~/.bashrc
state: present
regexp: '{{item.regexp}}'
line: '{{item.line}}'
loop:
- { line: 'export PATH="/home/{{username}}/.pyenv/bin:$PATH"', regexp: '{{username}}/.pyenv'}
- { line: 'eval "$(pyenv init -)"', regexp: 'pyenv init'}
- { line: 'eval "$(pyenv virtualenv-init -)"', regexp: 'virtualenv-init'}