mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-20 07:59:10 -07:00
parent
54384e7a12
commit
72fc11ff13
4 changed files with 27 additions and 3 deletions
|
@ -95,7 +95,7 @@ import os
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from ansible.errors import AnsibleFileNotFound, AnsibleParserError
|
from ansible.errors import AnsibleFileNotFound, AnsibleParserError
|
||||||
from ansible.module_utils._text import to_bytes, to_native
|
from ansible.module_utils._text import to_bytes, to_native, to_text
|
||||||
from ansible.module_utils.common._collections_compat import MutableMapping, MutableSequence
|
from ansible.module_utils.common._collections_compat import MutableMapping, MutableSequence
|
||||||
from ansible.module_utils.six import string_types, text_type
|
from ansible.module_utils.six import string_types, text_type
|
||||||
from ansible.parsing.yaml.objects import AnsibleSequence, AnsibleUnicode
|
from ansible.parsing.yaml.objects import AnsibleSequence, AnsibleUnicode
|
||||||
|
@ -211,8 +211,8 @@ class InventoryModule(BaseFileInventoryPlugin):
|
||||||
raise AnsibleFileNotFound("Unable to retrieve file contents", file_name=file_name)
|
raise AnsibleFileNotFound("Unable to retrieve file contents", file_name=file_name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(b_file_name, 'r') as f:
|
(b_data, private) = self.loader._get_file_contents(file_name)
|
||||||
return toml.load(f)
|
return toml.loads(to_text(b_data, errors='surrogate_or_strict'))
|
||||||
except toml.TomlDecodeError as e:
|
except toml.TomlDecodeError as e:
|
||||||
raise AnsibleParserError(
|
raise AnsibleParserError(
|
||||||
'TOML file (%s) is invalid: %s' % (file_name, to_native(e)),
|
'TOML file (%s) is invalid: %s' % (file_name, to_native(e)),
|
||||||
|
|
5
test/integration/targets/vault/inventory.toml
Normal file
5
test/integration/targets/vault/inventory.toml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[vauled_group.hosts]
|
||||||
|
vaulted_host_toml={ ansible_host="localhost", ansible_connection="local" }
|
||||||
|
|
||||||
|
[vauled_group.vars]
|
||||||
|
hello="world"
|
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -euvx
|
set -euvx
|
||||||
|
source virtualenv.sh
|
||||||
|
|
||||||
|
|
||||||
MYTMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
|
MYTMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
|
||||||
trap 'rm -rf "${MYTMPDIR}"' EXIT
|
trap 'rm -rf "${MYTMPDIR}"' EXIT
|
||||||
|
@ -404,6 +406,14 @@ ansible-playbook test_vault_embedded.yml -i ../../inventory -v "$@" --vault-pass
|
||||||
ansible-playbook test_vaulted_inventory.yml -i vaulted.inventory -v "$@" --vault-password-file vault-password
|
ansible-playbook test_vaulted_inventory.yml -i vaulted.inventory -v "$@" --vault-password-file vault-password
|
||||||
ansible-playbook test_vaulted_template.yml -i ../../inventory -v "$@" --vault-password-file vault-password
|
ansible-playbook test_vaulted_template.yml -i ../../inventory -v "$@" --vault-password-file vault-password
|
||||||
|
|
||||||
|
|
||||||
|
# install TOML for parse toml inventory
|
||||||
|
# test playbooks using vaulted files(toml)
|
||||||
|
pip install toml
|
||||||
|
ansible-vault encrypt ./inventory.toml -v "$@" --vault-password-file=./vault-password
|
||||||
|
ansible-playbook test_vaulted_inventory_toml.yml -i ./inventory.toml -v "$@" --vault-password-file vault-password
|
||||||
|
ansible-vault decrypt ./inventory.toml -v "$@" --vault-password-file=./vault-password
|
||||||
|
|
||||||
# test a playbook with a host_var whose value is non-ascii utf8 (see https://github.com/ansible/ansible/issues/37258)
|
# test a playbook with a host_var whose value is non-ascii utf8 (see https://github.com/ansible/ansible/issues/37258)
|
||||||
ansible-playbook -i ../../inventory -v "$@" --vault-id vault-password test_vaulted_utf8_value.yml
|
ansible-playbook -i ../../inventory -v "$@" --vault-id vault-password test_vaulted_utf8_value.yml
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
- hosts: vaulted_host_toml
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- name: See if we knew vaulted_host_toml
|
||||||
|
debug: msg="Found vaulted_host from vaulted.inventory.toml"
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'hello=="world"'
|
Loading…
Add table
Add a link
Reference in a new issue