1
0
Fork 0
mirror of https://github.com/DO1JLR/ansible_linux_desktop_setup.git synced 2024-09-14 19:54:51 +02:00

Merge pull request #6 from DO1JLR/y

optimize inv
This commit is contained in:
L3D 2023-04-21 23:37:01 +02:00 committed by GitHub
commit 7d259ecc50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,13 +24,16 @@ def fqdn():
hostname = f"{hostname}.local" hostname = f"{hostname}.local"
return str(hostname) return str(hostname)
def become_pass(host): def become_pass(host, group):
""" """
return variable for become password using gopass lookup return variable for become password using gopass lookup
""" """
passstring = str("\"ansible_become_pass\": " if group == 'work':
+ "\"{{ lookup('community.general.passwordstore', 'ansible/hosts/" gopasslookupprefix = 'private/ansible/hosts/'
+ host + "/users/root') }}\"") else:
gopasslookupprefix = 'ansible/hosts/'
passstring = str("\"ansible_become_pass\": \"{{ lookup('community.general.passwordstore', '"
+ gopasslookupprefix + host + "/users/root') }}\"")
return passstring return passstring
def env(domain): def env(domain):
@ -52,11 +55,12 @@ def empty_host_list(domain):
return json.loads('{"_meta": {"comment": "' + comment + return json.loads('{"_meta": {"comment": "' + comment +
'", "hostvars": {}}, "instances": {"hosts": []}}') '", "hostvars": {}}, "instances": {"hosts": []}}')
def hostvars(host): def hostvars(host, group):
""" """
set variables to local connection set variables to local connection
""" """
local = str('"' + host + '": {"ansible_connection": "local", ' + str(become_pass(host)) + '}') local = str('"' + host + '": {"ansible_connection": "local", '
+ str(become_pass(host, group)) + '}')
return local return local
def formated_host_group_list(host, group): def formated_host_group_list(host, group):
@ -64,7 +68,7 @@ def formated_host_group_list(host, group):
build inventory and return it build inventory and return it
""" """
# pylint: disable=line-too-long # pylint: disable=line-too-long
return json.loads('{"_meta": {"hostvars": {' + str(hostvars(host)) + '}},"' + str(group) + '": {"hosts": ["' + str(host) + '"]},"instances": {"children": ["' + str(group) + '"]}}') return json.loads('{"_meta": {"hostvars": {' + str(hostvars(host, group)) + '}},"' + str(group) + '": {"hosts": ["' + str(host) + '"]},"instances": {"children": ["' + str(group) + '"]}}')
def main(): def main():
""" """