Skip to content

Commit 9dc381e

Browse files
committed
fix hooks to not require APPLIANCES_ENVIRONMENT_ROOT env var
1 parent 06ccb87 commit 9dc381e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

ansible/site.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
- name: Run pre.yml hook
44
vars:
5-
appliances_environment_root: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}"
5+
# hostvars not available here, so have to recalculate environment root:
6+
appliances_environment_root: "{{ ansible_inventory_sources | last | dirname }}"
67
hook_path: "{{ appliances_environment_root }}/hooks/pre.yml"
78
import_playbook: "{{ hook_path if hook_path | exists else 'noop.yml' }}"
89
when: hook_path | exists
@@ -14,7 +15,8 @@
1415

1516
- name: Run post-bootstrap.yml hook
1617
vars:
17-
appliances_environment_root: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}"
18+
# hostvars not available here, so have to recalculate environment root:
19+
appliances_environment_root: "{{ ansible_inventory_sources | last | dirname }}"
1820
hook_path: "{{ appliances_environment_root }}/hooks/post-bootstrap.yml"
1921
import_playbook: "{{ hook_path if hook_path | exists else 'noop.yml' }}"
2022
when: hook_path | exists
@@ -28,7 +30,8 @@
2830

2931
- name: Run post.yml hook
3032
vars:
31-
appliances_environment_root: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}"
33+
# hostvars not available here, so have to recalculate environment root:
34+
appliances_environment_root: "{{ ansible_inventory_sources | last | dirname }}"
3235
hook_path: "{{ appliances_environment_root }}/hooks/post.yml"
3336
import_playbook: "{{ hook_path if hook_path | exists else 'noop.yml' }}"
3437
when: hook_path | exists

environments/.caas/hooks/pre.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
---
22

3+
- name: debug
4+
hosts:
5+
- localhost
6+
- openstack
7+
become: no
8+
gather_facts: no
9+
tasks:
10+
- debug:
11+
msg: "Starting pre-hook"
12+
313
# Provision the infrastructure using Terraform
414
- name: Provision infrastructure
515
hosts: openstack

0 commit comments

Comments
 (0)