-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-up.yml
106 lines (102 loc) · 3.16 KB
/
server-up.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
101
102
103
104
105
106
- hosts: localhost
gather_facts: no
environment:
OS_AUTH_URL: http://10.235.1.223/identity
OS_PROJECT_NAME: foodapp-dashboard
OS_USERNAME: admin
OS_PASSWORD: password
OS_USER_DOMAIN_NAME: Default
OS_PROJECT_DOMAIN_ID: default
tasks:
- name: Creating a new server and connecting it to the network dashboard-net (this may take some time)
openstack.cloud.server:
state: present
name: ubuntu
image: ubuntu-bionic-cloudimg
key_name: ansible_key
timeout: 200
flavor: m1.small
nics:
- net-name: dashboard-net
security_groups:
- dashboard-sg
- ssh-in
meta:
hostname: ubuntu-test
register: my_vm
- name: Adding VM to inventory (so I can connect to it later)
add_host:
name: dashboard_vm
groups: dashboard_vm
ansible_host: "{{ my_vm.server.public_v4 }}"
- name: Checking when the SSH server becomes available (so I know it has been provisioned)
local_action: "wait_for port=22 host={{ my_vm.server.public_v4 }}"
- hosts: dashboard_vm
gather_facts: no
remote_user: ubuntu
become: true
tasks:
- name: Waiting for connection to the NVM
wait_for_connection:
- name: Adding eval user
user:
name: eval
shell: /bin/bash
- name: Adding eval key to the eval user
ansible.posix.authorized_key:
user: eval
state: present
key: "{{ lookup('file', 'ssh_key.pub') }}"
- name: Installing nginx (needed for the frontend)
apt:
name: nginx
state: present
update_cache: yes
- name: Installing git
apt:
name: git
state: present
- name: Installing curl (to download node sources)
apt:
name: curl
state: present
- name: Downloading node
command: curl -sL https://deb.nodesource.com/setup_14.x -o node_setup.sh
args:
chdir: /home/ubuntu
- name: Configuring node setup
shell: bash ./node_setup.sh
args:
chdir: /home/ubuntu
- name: Installing node
apt:
name: nodejs
state: present
- name: Cloning dashboard frontend
git:
repo: https://github.com/riccardogilli/foodapp-dashboard-frontend.git
dest: /var/www/frontend
- name: Deploying dashboard frontend
copy:
remote_src: yes
src: /var/www/frontend/dist/
dest: /var/www/html
- name: Cloning dashboard backend
git:
repo: https://github.com/riccardogilli/foodapp-dashboard-backend.git
dest: /home/ubuntu/dashboard-backend
- name: Configuring dashboard backend (copying the .env.backend with the K8s paramters)
copy:
src: ./.env.backend
dest: /home/ubuntu/dashboard-backend/.env
- name: Running npm install for the backend
community.general.npm:
path: /home/ubuntu/dashboard-backend
- name: Installing pm2 (to run the node backend)
community.general.npm:
name: pm2
global: yes
- name: Running dashboard backend
command: pm2 start src/app.js --name node-backend
args:
chdir: /home/ubuntu/dashboard-backend