-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
100 lines (84 loc) · 2.53 KB
/
playbook.yml
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
---
# This file is provisioned upon `vagrant up` (via Vagrantfile),
# then it installs PostgreSQL and Docker to the guest OS.
# Or run as `vagrant provision`
# Or:
# ansible-playbook -i \
# .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory \
# playbook.yml
# Must be run from control node
# Target all hosts
- hosts: all
# Become default root user
become: true
vars_files:
- variables.yml
pre_tasks:
# Basic tools
- name: Install Basic Tools
ansible.builtin.apt:
name:
- htop
- net-tools
state: present
# PostgreSQL's prerequisites
- name: Install PostgreSQL Prerequisites
ansible.builtin.apt:
name:
- libpq-dev
- postgresql
- postgresql-contrib
- python3-psycopg2
state: present
# Docker's prerequisites
- name: Install Docker Prerequisites
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
state: present
tasks:
# Setup PostgreSQL
- name: Check PostgreSQL Init
ansible.builtin.stat:
# Register pg_hba.conf to variable
path: "{{ postgresql_data_dir }}/pg_hba.conf"
register: postgres_data
- name: Empty PostgreSQL Data
ansible.builtin.file:
path: "{{ postgresql_data_dir }}"
state: absent
when: not postgres_data.stat.exists
- name: Initialize PostgreSQL
ansible.builtin.shell: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}"
# Become postgres user
become: true
become_user: postgres
# Run if data directory nonexistent
when: not postgres_data.stat.exists
- name: Start PostgreSQL Service
ansible.builtin.service:
name: postgresql
state: started
enabled: true
# Begin installing Docker
- name: Add Docker apt-key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
- name: Add Docker Repository
ansible.builtin.apt_repository:
repo: deb https://download.docker.com/linux/ubuntu focal stable
- name: Install Docker
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
# Update sources after adding Docker repo
update_cache: yes
- name: Add User Permissions
# Add Vagrant user to Docker group
ansible.builtin.shell: "usermod -aG docker vagrant"