Skip to content

Commit 5dedb51

Browse files
aleskxyzdupondje
authored andcommitted
Add auth option templating
Signed-off-by: aleskxyz <[email protected]>
1 parent b88ec96 commit 5dedb51

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

plugins/inventory/ovirt.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
required: True
2626
choices: ['ovirt', 'ovirt.ovirt.ovirt', 'redhat.rhv.ovirt']
2727
ovirt_url:
28-
description: URL to ovirt-engine API.
28+
description: URL to ovirt-engine API. You can also use templating to specify the value of the O(ovirt_url).
2929
required: True
3030
env:
3131
- name: OVIRT_URL
3232
ovirt_username:
33-
description: ovirt authentication user.
33+
description: ovirt authentication user. You can also use templating to specify the value of the O(ovirt_username).
3434
required: True
3535
env:
3636
- name: OVIRT_USERNAME
3737
ovirt_password:
38-
description: ovirt authentication password.
38+
description: ovirt authentication password. You can also use templating to specify the value of the O(ovirt_password).
3939
required : True
4040
env:
4141
- name: OVIRT_PASSWORD
@@ -80,6 +80,20 @@
8080
dev: "'dev' in tags"
8181
compose:
8282
ansible_host: devices["eth0"][0]
83+
84+
# Specify `ovirt_url`, `ovirt_username`, and `ovirt_password` using templating or as an encrypted vault string
85+
# proxmox.yml
86+
plugin: @NAMESPACE@.@[email protected]
87+
ovirt_url: "{{ lookup('ansible.builtin.ini', 'url', section='ovirt', file='file.ini') }}"
88+
ovirt_username: "{{ lookup('ansible.builtin.env', 'OVIRT_USERNAME') | default('ansible@internal') }}"
89+
ovirt_password: !vault |
90+
$ANSIBLE_VAULT;1.1;AES256
91+
62353634333163633336343265623632626339313032653563653165313262343931643431656138
92+
6134333736323265656466646539663134306166666237630a653363623262636663333762316136
93+
34616361326263383766366663393837626437316462313332663736623066656237386531663731
94+
3037646432383064630a663165303564623338666131353366373630656661333437393937343331
95+
32643131386134396336623736393634373936356332623632306561356361323737313663633633
96+
6231313333666361656537343562333337323030623732323833
8397
'''
8498

8599
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
@@ -237,6 +251,13 @@ def parse(self, inventory, loader, path, cache=True):
237251

238252
config = self._read_config_data(path)
239253

254+
# Read and template auth options
255+
for auth_option_name in ('ovirt_url', 'ovirt_username', 'ovirt_password'):
256+
auth_option_value = self.get_option(auth_option_name)
257+
if self.templar.is_template(auth_option_value):
258+
auth_option_value = self.templar.template(auth_option_value, disable_lookups=False)
259+
self.set_option(auth_option_name, auth_option_value)
260+
240261
self.connection = sdk.Connection(
241262
url=self.get_option('ovirt_url'),
242263
username=self.get_option('ovirt_username'),

0 commit comments

Comments
 (0)