forked from brianehlert/ansible-nginx-controller-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx_controller_agent_2x.yaml
87 lines (73 loc) · 2.14 KB
/
nginx_controller_agent_2x.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
---
- hosts: localhost
vars_files:
- nginx_install_controller_vars.yaml
tasks:
- name: get controller internal DNS, written to hosts file
shell: cat "{{playbook_dir}}/controller"
register: controller
- name: set the controller private fqdn
set_fact:
controller_dns: "{{controller.stdout_lines[1]}}"
- debug:
var: controller_dns
- hosts: loadbalancers
remote_user: ubuntu
become: true
become_method: sudo
gather_facts: yes
tasks:
- name: install minimal support for python2 for Agent install script
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- python-minimal
# https://www.nginx.com/blog/monitoring-nginx/
- name: COPY stub_status.conf /etc/nginx/conf.d/
copy:
src: "{{playbook_dir}}/stub_status.conf"
dest: "/etc/nginx/conf.d/stub_status.conf"
force: yes
# necessary for process monitoring.
- name: COPY nginx-plus-api.conf /etc/nginx/conf.d/
copy:
src: "{{playbook_dir}}/nginx-plus-api.conf"
dest: "/etc/nginx/conf.d/nginx-plus-api.conf"
force: yes
- name: Get controller api key
uri:
url: "https://{{hostvars['localhost']['controller_dns']}}/sapi/auth/login/"
method: "POST"
body:
state:
email: "{{controller_user_email}}"
password: "{{controller_password}}"
body_format: json
return_content: yes
status_code: 200
validate_certs: false
register: controller_return
- name: Copy auth_token to a variable
set_fact:
api_key: "{{controller_return.json.api_key}}"
- name: download the installer script from controller
get_url:
url: "https://{{hostvars['localhost']['controller_dns']}}:8443/1.4/install/controller/"
dest: /home/ubuntu/install.sh
validate_certs: no
force: yes
register: controller_return
- name: run the Controller Agent installer
shell: "API_KEY={{api_key}} sh ./install.sh"
args:
chdir: /home/ubuntu
register: agent_install
- debug:
var: agent_install.stdout_lines
- name: restart nginx
service:
name=nginx
state=restarted