Skip to content

Commit 458cb75

Browse files
committedNov 30, 2020
Initial demo commit
1 parent 17fe256 commit 458cb75

37 files changed

+1504
-0
lines changed
 

Diff for: ‎.gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Any private crt and keys #
2+
############################
3+
*.crt
4+
*.key
5+
*~
6+
\#*
7+
8+
# NGINX Controller related installation files #
9+
###############################################
10+
*controller-installer*
11+
12+
# Terraform specific #
13+
######################
14+
.terraform
15+
*tfstate*
16+
*.tfvars
17+
18+
# Ansible specific #
19+
####################
20+
*.retry
21+
22+
# Log files #
23+
#############
24+
*.log
25+
26+
# OS Specific #
27+
###############
28+
.DS_Store

Diff for: ‎README.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# NGINX Controller Automation Demo
2+
3+
## Overview
4+
5+
This demo uses Packer, Terraform, and Ansible to automate the setup of an NGINX Controller AWS pseudo-production environment that includes a PostgreSQL external database, a mock SMTP server, and a series of NGINX Plus instances.
6+
7+
## Requirements
8+
9+
### Packer
10+
11+
This demo has been developed and tested with Packer `1.6.x`. Backwards compatibility is not guaranteed.
12+
13+
Instructions on how to install Packer can be found in the [Packer website](https://www.packer.io/downloads.html).
14+
15+
### Terraform
16+
17+
This demo has been developed and tested with Terraform `0.13.x`. Backwards compatibility is not guaranteed.
18+
19+
Instructions on how to install Terraform can be found in the [Terraform website](https://www.terraform.io/downloads.html).
20+
21+
### Ansible
22+
23+
This demo has been developed and tested with Ansible `2.10.x`. Backwards compatibility is not guaranteed.
24+
25+
Instructions on how to install Ansible can be found in the [Ansible website](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html).
26+
27+
### NGINX Controller & NGINX Plus
28+
29+
You will need to download the NGINX Controller tar file, NGINX Controller license, and NGINX Plus license from your [MyF5 portal](https://account.f5.com/myf5) before you run this script.
30+
31+
You will also need a FQDN for NGINX Controller with its `A record` pointing to an AWS elastic IP.
32+
33+
## Guide
34+
35+
There are three "distinct" steps to this NGINX Controller automation demo:
36+
37+
1. **Packer** prebuilds AWS AMIs (using the Ansible provisioner) for PostgreSQL, a mock SMTP server, NGINX Controller, and NGINX Plus. Packer templates (and the corresponding Ansible playbooks used by Packer) can be found in the [`packer/`](packer/) directory.
38+
2. **Terraform** deploys a pseudo-production ready NGINX Controller infrastructure environment in AWS using the AWS AMIs created by Packer. Terraform modules can be found in the [`terraform/`](terraform/) directory.
39+
3. **Ansible** installs and configures NGINX Controller on the NGINX Controller instance and the NGINX Controller agent on the NGINX Plus instance. Ansible playbooks can be found in the [`ansible/`](ansible/) directory.
40+
41+
In turn, there are four "distinct" components deployed in this NGINX Controller automation demo:
42+
43+
1. **NGINX Controller**
44+
2. **NGINX Plus instance(s)**
45+
3. **PostgreSQL database**
46+
4. **Mock SMTP server**
47+
48+
Both Packer and Terraform have been separated into logical subdirectories following the above four "distinct" components.
49+
50+
For ease of use, both the Packer and Ansible steps have been included in the Terraform script at the top and bottom of [`main.tf`](main.tf) respectively. However, you can decouple Packer and Ansible from Terraform setting the `run_packer` and `run_ansible` variables to `false` within your Terraform variables, and then running each step separately as detailed below.
51+
52+
### Packer
53+
54+
To use the provided Packer templates, you will first need to:
55+
56+
1. Export your AWS credentials as environment variables (or alternatively, use one of the authentication methods described in the [Packer AWS builder docs](https://www.packer.io/docs/builders/amazon).
57+
2. Tweak any desired variables (detailed within each respective Packer template). Alternatively, you can input those variables at runtime.
58+
59+
There are four Packer templates in this demo:
60+
61+
|Name|Description|
62+
|----|-----------|
63+
|[`nginx.pkr.hcl`](packer/nginx/nginx.pkr.hcl)|Build an NGINX Plus AMI|
64+
|[`nginx-controller.pkr.hcl`](packer/nginx-controller/nginx-controller.pkr.hcl)|Build an NGINX Controller AMI|
65+
|[`postgresql.pkr.hcl`](packer/postgresql/postgresql.pkr.hcl)|Build a PostgreSQL database|
66+
|[`smtp.pkr.hcl`](packer/smtp/smtp.pkr.hcl)|Build a mock SMTP server|
67+
68+
To start a Packer build, run:
69+
70+
```
71+
packer build packer/<subdirectory>/<template>.pkr.hcl
72+
```
73+
74+
(**Note:** Both the `nginx-controller.pkr.hcl` and `nginx.pkr.hcl` Packer templates require you to explicitly set some variables.)
75+
76+
### Terraform
77+
78+
To use the provided Terraform deployment, you will first need to:
79+
80+
1. Export your AWS credentials as environment variables (or alternatively, tweak the AWS provider in [`provider.tf`](provider.tf)).
81+
2. Tweak any desired variables in [`variables.tf`](variables.tf). Alternatively, you can input those variables at runtime.
82+
83+
There are five Terraform modules in this demo:
84+
85+
|Name|Description|
86+
|----|-----------|
87+
|[`network/`](terraform/network/)|Deploy NGINX Controller's network stack|
88+
|[`nginx-controller/`](terraform/nginx-controller/)|Deploy NGINX Controller instance and relevant network components|
89+
|[`nginx/`](terraform/nginx/)|Deploy NGINX Plus instance(s) and relevant network components|
90+
|[`postgresql/`](terraform/postgresql/)|Deploy PostgreSQL instance|
91+
|[`smtp/`](terraform/smtp/)|Deploy mock SMTP instance|
92+
93+
To start the AWS NGINX Controller deployment, you can either:
94+
95+
* Run [`./setup.sh`](setup.sh) to initialize Terraform and start the Terraform deployment.
96+
* Run `terraform init` and `terraform apply`.
97+
98+
Once you are done playing with NGINX Controller, you can destroy the AWS NGINX Controller deployment by either:
99+
100+
* Run [`./cleanup.sh`](cleanup.sh) to destroy your Terraform deployment.
101+
* Run `terraform destroy` (you can optionally delete your `.terraform` directory too).
102+
103+
### Ansible
104+
105+
To use the provided Ansible playbooks, you will first need to install the required collections/roles by running:
106+
107+
```
108+
ansible-galaxy install -r ansible/requirements.yml
109+
```
110+
111+
There are two Ansible playbooks in this demo:
112+
113+
|Name|Description|
114+
|----|-----------|
115+
|[`nginx-controller-install.yml`](ansible/nginx-controller-install.yml)|Install and configure NGINX Controller|
116+
|[`nginx-controller-agent.yml`](ansible/nginx-controller-agent.yml)|Install and configure the NGINX Controller agent|
117+
118+
To execute a playbook, run:
119+
120+
```
121+
ansible-playbook --private-key=</path/to/key> -i </instance/ip>, -u ubuntu ansible/<playbook>.yml
122+
```
123+
124+
(**Note:** You will first need to install and configure NGINX Controller using the `nginx-controller-install.yml` playbook before you can install the NGINX Controller agent on NGINX Plus instances using the `nginx-controller-agent.yml` playbook.)
125+
126+
## Author Information
127+
128+
[Alessandro Fael Garcia](https://github.com/alessfg)

Diff for: ‎ansible/nginx-controller-agent.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
- name: Install the NGINX Controller agent
2+
hosts: all
3+
become: true
4+
collections:
5+
- nginxinc.nginx_controller
6+
vars:
7+
nginx_controller_fqdn: "{{ controller_fqdn }}"
8+
tasks:
9+
- name: Retrieve the NGINX Controller auth token
10+
include_role:
11+
name: nginx_controller_generate_token
12+
vars:
13+
nginx_controller_user_email: john.doe@f5.com
14+
nginx_controller_user_password: password123
15+
- name: Fetch the NGINX Controller API key for agent registration
16+
uri:
17+
url: "https://{{ controller_fqdn }}/api/v1/platform/global"
18+
method: GET
19+
return_content: yes
20+
status_code: 200
21+
validate_certs: false
22+
headers:
23+
Cookie: "{{ nginx_controller_auth_token }}"
24+
register: ctrl_globals
25+
- name: Install the NGINX Controller agent
26+
include_role:
27+
name: nginx_controller_agent
28+
vars:
29+
nginx_controller_api_key: "{{ ctrl_globals.json.currentStatus.agentSettings.apiKey }}"

Diff for: ‎ansible/nginx-controller-install.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- name: Set up NGINX Controller
2+
hosts: all
3+
collections:
4+
- nginxinc.nginx_controller
5+
tasks:
6+
- name: Install NGINX Controller
7+
include_role:
8+
name: nginx_controller_install
9+
vars:
10+
nginx_controller_tarball: "{{ nginx_controller_tarball_location }}"
11+
nginx_controller_remote_source: true
12+
nginx_controller_install_path: /home/ubuntu
13+
nginx_controller_fqdn: "{{ nginx_controller_fqdn }}"
14+
nginx_controller_db_host: "{{ nginx_controller_db_host }}"
15+
nginx_controller_db_user: naas
16+
nginx_controller_db_password: naas
17+
nginx_controller_db_enable_ssl: false
18+
nginx_controller_tsdb_volume_type: local
19+
nginx_controller_smtp_host: "{{ nginx_controller_smtp_host | default('localhost') }}"
20+
nginx_controller_smtp_authentication: false
21+
nginx_controller_smtp_use_tls: false
22+
nginx_controller_noreply_address: noreply@f5.com
23+
nginx_controller_organization_name: F5
24+
nginx_controller_admin_firstname: John
25+
nginx_controller_admin_lastname: Doe
26+
nginx_controller_admin_email: john.doe@f5.com
27+
nginx_controller_admin_password: password123
28+
nginx_controller_self_signed_cert: true
29+
nginx_controller_auto_install_docker: true
30+
- name: Retrieve the NGINX Controller auth token
31+
include_role:
32+
name: nginx_controller_generate_token
33+
vars:
34+
nginx_controller_fqdn: localhost
35+
nginx_controller_user_email: john.doe@f5.com
36+
nginx_controller_user_password: password123
37+
- name: License NGINX Controller
38+
include_role:
39+
name: nginx_controller_license
40+
vars:
41+
nginx_controller_fqdn: localhost
42+
nginx_controller_license: "{{ lookup('file', nginx_controller_license_location) | b64encode }}"

Diff for: ‎ansible/requirements.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
collections:
3+
- name: nginxinc.nginx_controller
4+
version: 3.7.5

Diff for: ‎cleanup.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
terraform destroy -auto-approve \
2+
&& rm -rf .terraform

0 commit comments

Comments
 (0)