Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added configuration to temporarily disable the vars plugin (eg in AWX). #114

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/114-disable-vars-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "sops vars plugin - added a configuration option to temporarily disable the vars plugin (https://github.com/ansible-collections/community.sops/pull/114)."
12 changes: 12 additions & 0 deletions plugins/vars/sops.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
section: community.sops
env:
- name: ANSIBLE_VARS_SOPS_PLUGIN_CACHE
_disable_vars_plugin_temporarily:
description:
- Temporarily disable this plugin.
- Useful if ansible-inventory is supposed to be run without decrypting secrets (in AWX for instance).
type: bool
default: false
version_added: 1.3.0
env:
- name: SOPS_ANSIBLE_AWX_DISABLE_VARS_PLUGIN_TEMPORARILY
extends_documentation_fragment:
- ansible.builtin.vars_plugin_staging
- community.sops.sops
Expand Down Expand Up @@ -90,6 +99,9 @@ def get_option_value(argument_name):
if cache is None:
cache = self.get_option('cache')

if self.get_option('_disable_vars_plugin_temporarily'):
return {}

data = {}
for entity in entities:
if isinstance(entity, Host):
Expand Down
1 change: 1 addition & 0 deletions tests/integration/targets/var_sops/test-disable-sops/hosts
11 changes: 11 additions & 0 deletions tests/integration/targets/var_sops/test-disable-sops/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

- hosts: localhost
gather_facts: false
tasks:
- name: Make sure group_vars/all.sops.yaml was not loaded.
debug:
msg: '{{ foo }}' # Will throw an undefined error.
8 changes: 8 additions & 0 deletions tests/integration/targets/var_sops/test-disable-sops/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

set -e
SOPS_ANSIBLE_AWX_DISABLE_VARS_PLUGIN_TEMPORARILY=true \
ansible-playbook playbook.yml -i hosts -v "$@"
12 changes: 12 additions & 0 deletions tests/integration/targets/var_sops/test-disable-sops/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

set -eux

if [ "$1" != 2 ]; then
exit 1
fi

grep -F "The error was: 'foo' is undefined" "$2"