Skip to content

Commit

Permalink
B #99: Correctly handle vault-encrypted values in inventory
Browse files Browse the repository at this point in the history
- Make sure precheck role doesn't fail
- Extend Makefile so it detects if --ask-vault-pass is required
  • Loading branch information
sk4zuzu committed Feb 13, 2025
1 parent 5ead565 commit 8034329
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ all: main
infra pre ceph site main: _TAGS := $(if $(TAGS),-t $(TAGS),)
infra pre ceph site main: _SKIP_TAGS := $(if $(SKIP_TAGS),--skip-tags $(SKIP_TAGS),)
infra pre ceph site main: _VERBOSE := $(if $(VERBOSE),-$(VERBOSE),)
infra pre ceph site main: _ASK_VAULT := $(if $(findstring $$ANSIBLE_VAULT;,$(file < $(INVENTORY))),--ask-vault-pass,)

ifdef ENV_DEFAULT
$(ENV_DEFAULT):
Expand All @@ -43,7 +44,7 @@ endif

infra pre site main: $(ENV_DEFAULT)
cd $(SELF)/ && \
$(call ENV_RUN,default) ansible-playbook $(_VERBOSE) -i $(INVENTORY) $(_TAGS) $(_SKIP_TAGS) opennebula.deploy.$@
$(call ENV_RUN,default) ansible-playbook $(_VERBOSE) -i $(INVENTORY) $(_ASK_VAULT) $(_TAGS) $(_SKIP_TAGS) opennebula.deploy.$@

ifdef ENV_CEPH
$(ENV_CEPH):
Expand All @@ -52,7 +53,7 @@ endif

ceph: $(ENV_CEPH)
cd $(SELF)/ && \
$(call ENV_RUN,ceph) ansible-playbook $(_VERBOSE) -i $(INVENTORY) $(_TAGS) $(_SKIP_TAGS) opennebula.deploy.$@
$(call ENV_RUN,ceph) ansible-playbook $(_VERBOSE) -i $(INVENTORY) $(_ASK_VAULT) $(_TAGS) $(_SKIP_TAGS) opennebula.deploy.$@

.PHONY: requirements requirements-hatch requirements-python requirements-galaxy clean-requirements

Expand Down
10 changes: 6 additions & 4 deletions roles/precheck/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
msg: Please use ansible version >= 2.14.0.
run_once: true

- name: Ensure string type for critical vars
- name: Ensure correct type for critical vars
ansible.builtin.assert:
that:
- context.PASSWORD is undefined or context.PASSWORD is string
- one_pass is undefined or one_pass is none or one_pass is string
or context.PASSWORD | type_debug == 'AnsibleVaultEncryptedUnicode'
- one_pass is undefined or one_pass is string
or one_pass | type_debug == 'AnsibleVaultEncryptedUnicode'
or one_pass is none
- one_token is undefined or one_token is string
or one_token | type_debug == 'AnsibleVaultEncryptedUnicode'
- one_version is string
msg: Please make sure [context.PASSWORD, one_pass, one_token, one_version] are valid strings.
run_once: true

- name: Validate passwords strength
ansible.builtin.assert:
Expand Down Expand Up @@ -53,7 +56,6 @@
when:
- prod_env | d(false) | bool is true
- _items[item].condition
run_once: true

- name: Check if one_vip/force_ha settings are valid
ansible.builtin.assert:
Expand Down

0 comments on commit 8034329

Please # to comment.