Skip to content

Commit 25786a7

Browse files
authored
Merge pull request #25 from stackhpc/jph/designate
Add support for FQDNs, Designate and Dynamic Inventories
2 parents 6e3f10f + ff787f7 commit 25786a7

File tree

12 files changed

+154
-56
lines changed

12 files changed

+154
-56
lines changed

.terraform.lock.hcl

Lines changed: 36 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.rst

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ Finally run the ansible playbooks.
201201
You may need to run `fix-homedir-ownership.yml` if you are using an image that has `ansible_user` not owning their own home folder.
202202
You may also need to run `grow-control-host.yml` if you are using LVM images and the LVMs are too small to install Ansible.
203203
If not you can skip those playbook and proceed onto `deploy-openstack-config` which shall configure your Ansible control host in preparation for deployment.
204-
Be sure to replace `ansible_user` with the user you are using to connect to the Ansible control host.
204+
205205
.. code-block:: console
206206
207-
ansible-playbook -i $(terraform output -raw ansible_control_access_ip_v4), ansible/fix-homedir-ownership.yml -e ansible_user=cloud-user
208-
ansible-playbook -i $(terraform output -raw ansible_control_access_ip_v4), ansible/grow-control-host.yml -e ansible_user=cloud-user
209-
ansible-playbook -i $(terraform output -raw ansible_control_access_ip_v4), ansible/deploy-openstack-config.yml -e ansible_user=cloud-user
207+
ansible-playbook -i ansible/inventory.yml ansible/fix-homedir-ownership.yml
208+
ansible-playbook -i ansible/inventory.yml ansible/add-fqdn.yml
209+
ansible-playbook -i ansible/inventory.yml ansible/grow-control-host.yml
210+
ansible-playbook -i ansible/inventory.yml ansible/deploy-openstack-config.yml
210211
211212
Deploy OpenStack
212213
----------------
@@ -219,7 +220,7 @@ If you choose to opt for automated method you must first SSH into your Ansible c
219220

220221
.. code-block:: console
221222
222-
ssh ${ssh_user}@${ansible_ip}
223+
ssh $(terraform output -raw ssh_user)@$(terraform output -raw ansible_control_access_ip_v4)
223224
~/deploy-openstack.sh
224225
225226
This script will go through the process of performing the following tasks
@@ -231,6 +232,23 @@ This script will go through the process of performing the following tasks
231232
* openstack configuration
232233
* tempest testing
233234

235+
Accessing OpenStack
236+
-------------------
237+
238+
After a successful deployment of OpenStack you make access the OpenStack API and Horizon by proxying your connection via the seed node, as it has an interface on the public network (192.168.39.X).
239+
Using software such as sshuttle will allow for easy access.
240+
241+
.. code-block:: console
242+
243+
sshuttle -r $(terraform output -raw ssh_user)@$(terraform output -raw seed_access_ip_v4) 192.168.39.0/24
244+
245+
You may also use sshuttle to proxy DNS via the multinode environment. Useful if you are working with Designate.
246+
Important to node this will proxy all DNS requests from your machine to the first controller within the multinode environment.
247+
248+
.. code-block:: console
249+
250+
sshuttle -r $(terraform output -raw ssh_user)@$(terraform output -raw seed_access_ip_v4) 192.168.39.0/24 --dns --to-ns 192.168.39.4
251+
234252
Tear Down
235253
---------
236254

ansible/add-fqdn.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
- name: Add FQDN to hosts
3+
hosts: all
4+
gather_facts: false
5+
vars_files:
6+
- vars/defaults.yml
7+
tasks:
8+
- name: Ensure OS FQDN are added to /etc/hosts
9+
ansible.builtin.lineinfile:
10+
path: "/etc/hosts"
11+
line: "{{ item }}"
12+
loop:
13+
- "192.168.37.2 internal.infra.mos.{{ root_domain }}"
14+
- "192.168.39.2 public.infra.mos.{{ root_domain }}"
15+
tags: hosts
16+
become: true

ansible/deploy-openstack-config.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Deploy OpenStack Configuration
3-
hosts: all
3+
hosts: ansible_control
44
gather_facts: false
55
vars_files:
66
- vars/defaults.yml
@@ -17,20 +17,10 @@
1717
- vxlan_vni != None
1818
fail_msg: "Please provide a VXLAN VNI. A unique value from 1 to 100,000."
1919

20-
- name: Ensure Ansible host is reachable
21-
ansible.builtin.wait_for_connection:
22-
2320
- name: Gather facts about the host
2421
ansible.builtin.setup:
25-
26-
- name: Ensure hosts are reachable
27-
ansible.builtin.command:
28-
cmd: "ping -c 1 -w 2 {{ item.value }}"
29-
loop: "{{ (lookup('file', 'files/admin-oc-networks.yml') | from_yaml).admin_oc_ips | dict2items }}"
30-
changed_when: false
31-
register: ping_results
32-
retries: 3
33-
until: ping_results is succeeded
22+
gather_subset:
23+
- user_dir
3424

3525
- name: Ensure git is present
3626
ansible.builtin.package:
@@ -91,12 +81,17 @@
9181
dest: "{{ src_directory }}/{{ kayobe_config_name }}/etc/kayobe/environments/{{ kayobe_config_environment }}/inventory/hosts"
9282
mode: "0644"
9383

84+
- name: Ensure root_domain is defined
85+
ansible.builtin.lineinfile:
86+
path: "{{ src_directory }}/{{ kayobe_config_name }}/etc/kayobe/environments/{{ kayobe_config_environment }}/inventory/group_vars/all/main.yml"
87+
line: "root_domain: {{ root_domain }}"
88+
9489
- name: Ensure hosts are added to /etc/hosts
95-
become: true
9690
ansible.builtin.lineinfile:
9791
path: "/etc/hosts"
9892
line: "{{ item.value }}\t{{ item.key }}"
9993
loop: "{{ (lookup('file', 'files/admin-oc-networks.yml') | from_yaml).admin_oc_ips | dict2items }}"
94+
become: true
10095

10196
- name: Ensure VXLAN VNI has been set
10297
ansible.builtin.lineinfile:

ansible/fix-homedir-ownership.yml

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
---
22
- name: Fix Home Directory Ownership
33
hosts: all
4-
gather_facts: true
5-
vars_files:
6-
- files/admin-oc-networks.yml
4+
gather_facts: false
75
vars:
86
# At the time of running this playbook the home directory is not owned by the user.
97
# Therefore, we will not be permitted to store the Ansible temporary directory in the home folder.
108
# This must be relocated to some where that can be written to by the remote user.
119
ansible_remote_tmp: "/tmp/ansible"
1210
tasks:
1311
- name: Ensure hosts are reachable
14-
ansible.builtin.command:
15-
cmd: "ping -c 1 -w 2 {{ item.value }}"
16-
loop:
17-
"{{ (lookup('file', 'files/admin-oc-networks.yml') | from_yaml).admin_oc_ips | dict2items }}"
18-
changed_when: false
19-
register: ping_results
20-
retries: 15
21-
delay: 3
22-
until: ping_results is succeeded
12+
ansible.builtin.wait_for_connection:
2313

24-
- name: Ensure homedir of ansible control node is owned by cloud-user # noqa: no-changed-when
25-
ansible.builtin.command:
26-
cmd: "sudo chown -R cloud-user: ."
14+
- name: Gather the home directory of the user
15+
ansible.builtin.setup:
16+
gather_subset:
17+
- user_dir
2718

28-
- name: Ensure homedir of all nodes is owned by cloud-user # noqa: no-changed-when
29-
ansible.builtin.command:
30-
cmd: "ssh -oStrictHostKeyChecking=no cloud-user@{{ item.value }} sudo chown -R cloud-user: ."
31-
loop: "{{ (lookup('file', 'files/admin-oc-networks.yml') | from_yaml).admin_oc_ips | dict2items }}"
32-
delegate_to: localhost
19+
- name: Ensure homedir is owned by {{ ansible_user }}
20+
ansible.builtin.file:
21+
dest: "{{ ansible_env.HOME }}"
22+
state: directory
23+
owner: "{{ ansible_user }}"
24+
group: "{{ ansible_user }}"
25+
mode: "0755"
26+
become: true

ansible/grow-control-host.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Grow Control Host
3-
hosts: all
3+
hosts: ansible_control
44
gather_facts: true
55
vars_files:
66
- vars/defaults.yml

ansible/inventory.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
plugin: cloud.terraform.terraform_provider

ansible/requirements.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
---
2+
collections:
3+
- name: cloud.terraform
24
roles:
3-
- src: mrlesmithjr.manage-lvm
5+
- src: mrlesmithjr.manage_lvm

ansible/vars/defaults.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ ssh_key_path:
2020

2121
vxlan_vni:
2222

23+
root_domain: sms-lab.cloud
24+
2325
lvm_groups:
2426
- vgname: rootvg
2527
disks:

outputs.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ output "ansible_control_access_ip_v4" {
22
value = openstack_compute_instance_v2.ansible_control.access_ip_v4
33
}
44

5+
output "seed_access_ip_v4" {
6+
value = openstack_compute_instance_v2.seed.access_ip_v4
7+
}
8+
9+
output "ssh_user" {
10+
value = var.ssh_user
11+
}
12+
513
resource "local_file" "hosts" {
614
content = templatefile(
715
"${path.module}/templates/hosts.tpl",
@@ -66,3 +74,39 @@ resource "local_file" "deploy_openstack" {
6674
filename = "ansible/files/deploy-openstack.sh"
6775
file_permission = "0755"
6876
}
77+
78+
resource "ansible_host" "control_host" {
79+
name = openstack_compute_instance_v2.ansible_control.access_ip_v4
80+
groups = ["ansible_control"]
81+
}
82+
83+
resource "ansible_host" "compute_host" {
84+
for_each = { for host in openstack_compute_instance_v2.compute : host.name => host.access_ip_v4 }
85+
name = each.value
86+
groups = ["compute"]
87+
}
88+
89+
resource "ansible_host" "controllers_hosts" {
90+
for_each = { for host in openstack_compute_instance_v2.controller : host.name => host.access_ip_v4 }
91+
name = each.value
92+
groups = ["controllers"]
93+
}
94+
95+
resource "ansible_host" "seed_host" {
96+
name = openstack_compute_instance_v2.seed.access_ip_v4
97+
groups = ["seed"]
98+
}
99+
100+
resource "ansible_host" "storage" {
101+
for_each = { for host in openstack_compute_instance_v2.storage : host.name => host.access_ip_v4 }
102+
name = each.value
103+
groups = ["storage"]
104+
}
105+
106+
resource "ansible_group" "cluster_group" {
107+
name = "cluster"
108+
children = ["compute", "ansible_control", "controllers", "seed", "storage"]
109+
variables = {
110+
ansible_user = var.ssh_user
111+
}
112+
}

0 commit comments

Comments
 (0)