Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
rbfsmi.imt
rbfsmi-ansible
Commits
0e91586e
Verified
Commit
0e91586e
authored
Feb 26, 2021
by
Philipp Michael Breuch
Browse files
inventory: Add !vault yaml tag
Otherwise the inventory script will stacktrace while parsing !vault tags
parent
48714dfe
Changes
1
Hide whitespace changes
Inline
Side-by-side
inventory
View file @
0e91586e
...
...
@@ -8,6 +8,30 @@ import json
import
argparse
import
collections
as
coll
# https://stackoverflow.com/questions/43058050/creating-custom-tag-in-pyyaml
class
VaultTag
(
yaml
.
YAMLObject
):
yaml_tag
=
u
'!vault'
def
__init__
(
self
,
env_var
):
self
.
env_var
=
env_var
def
__repr__
(
self
):
v
=
os
.
environ
.
get
(
self
.
env_var
)
or
''
return
'VaultTag({}, contains={})'
.
format
(
self
.
env_var
,
v
)
@
classmethod
def
from_yaml
(
cls
,
loader
,
node
):
return
VaultTag
(
node
.
value
)
@
classmethod
def
to_yaml
(
cls
,
dumper
,
data
):
return
dumper
.
represent_scalar
(
cls
.
yaml_tag
,
data
.
env_var
)
# Required for safe_load
yaml
.
SafeLoader
.
add_constructor
(
'!vault'
,
VaultTag
.
from_yaml
)
inventory_defaults
=
{
'ansible_ssh_port'
:
22022
,
'ansible_ssh_user'
:
'root'
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment