feat: can remove namespace name in host vars
This commit is contained in:
parent
58b68a9627
commit
6c0cb52c69
5 changed files with 50 additions and 36 deletions
|
|
@ -5,8 +5,8 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"POT-Creation-Date: 2025-07-03 22:11+0300\n"
|
||||
"PO-Revision-Date: 2025-07-03 22:11+0300\n"
|
||||
"POT-Creation-Date: 2025-11-21 08:24+0100\n"
|
||||
"PO-Revision-Date: 2025-11-21 08:24+0100\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"Language: fr\n"
|
||||
|
|
@ -14,23 +14,23 @@ msgstr ""
|
|||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Generated-By: pygettext.py 1.5\n"
|
||||
"X-Generator: Poedit 3.6\n"
|
||||
"X-Generator: Poedit 3.8\n"
|
||||
|
||||
#: src/rougail/output_ansible/__init__.py:58
|
||||
#: src/rougail/output_ansible/__init__.py:59
|
||||
msgid "no namespace configured"
|
||||
msgstr "aucun espace de nom configuré"
|
||||
|
||||
#: src/rougail/output_ansible/__init__.py:67
|
||||
#: src/rougail/output_ansible/__init__.py:68
|
||||
msgid "cannot find host namespace \"{0}\""
|
||||
msgstr "ne peut trouve l'espace de nom de l'hôte \"{0}\""
|
||||
|
||||
#: src/rougail/output_ansible/__init__.py:74
|
||||
#: src/rougail/output_ansible/__init__.py:75
|
||||
msgid "malformated host namespace \"{0}\", should have the \"hostnames\" key"
|
||||
msgstr ""
|
||||
"l'espace de nom de l'hôte \"{0}\" est mal formaté, devrait avoir la clé "
|
||||
"\"hostnames\""
|
||||
|
||||
#: src/rougail/output_ansible/__init__.py:113
|
||||
#: src/rougail/output_ansible/__init__.py:105
|
||||
msgid "cannot find \"hostnames\" in \"{0}\" namespace"
|
||||
msgstr "ne peut trouve \"hostnames\" dans l'espace de nom \"{0}\""
|
||||
|
||||
|
|
@ -42,23 +42,26 @@ msgstr "paramètre ajouté seulement pour être compatible avec Ansible"
|
|||
msgid "Configuration of user data or output Ansible"
|
||||
msgstr "Configuration de Ansible comme donnée utilisateur ou sortie"
|
||||
|
||||
#: src/rougail/output_ansible/config.py:64
|
||||
#: src/rougail/output_ansible/config.py:65
|
||||
msgid "Configuration of output Ansible"
|
||||
msgstr "Configuration de la sortie Ansible"
|
||||
|
||||
#: src/rougail/output_ansible/config.py:76
|
||||
#: src/rougail/output_ansible/config.py:77
|
||||
msgid "Namespace with host values"
|
||||
msgstr "Espace de nom avec les valeurs de l'hôte"
|
||||
|
||||
#: src/rougail/output_ansible/config.py:80
|
||||
msgid "Only variables in host namespace is available by a host"
|
||||
msgstr ""
|
||||
"Seules les variables de l'espace de nom de l'hôte est valable pour un hôte"
|
||||
#: src/rougail/output_ansible/config.py:81
|
||||
msgid "Remove namespace name in host vars"
|
||||
msgstr "Supprime le nom de l'espace de nom dans les vars de l'hôte"
|
||||
|
||||
#: src/rougail/output_ansible/config.py:84
|
||||
#: src/rougail/output_ansible/config.py:85
|
||||
msgid "Displays warnings inside Ansible exportation datas"
|
||||
msgstr "Affiche les avertissements dans les données d'exportation Ansible"
|
||||
|
||||
#~ msgid "Only variables in host namespace is available by a host"
|
||||
#~ msgstr ""
|
||||
#~ "Seules les variables de l'espace de nom de l'hôte est valable pour un hôte"
|
||||
|
||||
#~ msgid "All variables is available for all hosts"
|
||||
#~ msgstr "Tous les variables sont valables pour tous les hôtes"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"POT-Creation-Date: 2025-07-03 22:11+0300\n"
|
||||
"POT-Creation-Date: 2025-11-21 08:24+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
|
@ -15,19 +15,19 @@ msgstr ""
|
|||
"Generated-By: pygettext.py 1.5\n"
|
||||
|
||||
|
||||
#: src/rougail/output_ansible/__init__.py:58
|
||||
#: src/rougail/output_ansible/__init__.py:59
|
||||
msgid "no namespace configured"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/output_ansible/__init__.py:67
|
||||
#: src/rougail/output_ansible/__init__.py:68
|
||||
msgid "cannot find host namespace \"{0}\""
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/output_ansible/__init__.py:74
|
||||
#: src/rougail/output_ansible/__init__.py:75
|
||||
msgid "malformated host namespace \"{0}\", should have the \"hostnames\" key"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/output_ansible/__init__.py:113
|
||||
#: src/rougail/output_ansible/__init__.py:105
|
||||
msgid "cannot find \"hostnames\" in \"{0}\" namespace"
|
||||
msgstr ""
|
||||
|
||||
|
|
@ -39,19 +39,19 @@ msgstr ""
|
|||
msgid "Configuration of user data or output Ansible"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/output_ansible/config.py:64
|
||||
#: src/rougail/output_ansible/config.py:65
|
||||
msgid "Configuration of output Ansible"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/output_ansible/config.py:76
|
||||
#: src/rougail/output_ansible/config.py:77
|
||||
msgid "Namespace with host values"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/output_ansible/config.py:80
|
||||
msgid "Only variables in host namespace is available by a host"
|
||||
#: src/rougail/output_ansible/config.py:81
|
||||
msgid "Remove namespace name in host vars"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/output_ansible/config.py:84
|
||||
#: src/rougail/output_ansible/config.py:85
|
||||
msgid "Displays warnings inside Ansible exportation datas"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
|||
|
|
@ -43,11 +43,11 @@ class RougailOutputAnsible(RougailOutputJson):
|
|||
self.support_namespace = True
|
||||
except AttributeError:
|
||||
self.support_namespace = False
|
||||
self.host_namespace = self.rougailconfig["ansible.host_namespace"]
|
||||
self.namespace_is_hostname = self.rougailconfig["ansible.namespace_is_hostname"]
|
||||
self.export_warnings = self.rougailconfig["ansible.export_warnings"]
|
||||
|
||||
def exporter(self) -> None:
|
||||
self.host_namespace = self.rougailconfig["ansible.host_namespace"]
|
||||
self.export_warnings = self.rougailconfig["ansible.export_warnings"]
|
||||
self.no_namespace_in_vars = self.rougailconfig["ansible.no_namespace_in_vars"]
|
||||
super().exporter()
|
||||
self.json_to_ansible()
|
||||
# never return code 1, error are in the output data
|
||||
|
|
@ -76,11 +76,13 @@ class RougailOutputAnsible(RougailOutputJson):
|
|||
'malformated host namespace "{0}", should have the "hostnames" key'
|
||||
).format(self.host_namespace)
|
||||
)
|
||||
# error is added, so replay manage_errors
|
||||
return super().manage_errors()
|
||||
return True
|
||||
|
||||
def json_to_ansible(self):
|
||||
ret = {"_meta": {"hostvars": {}}}
|
||||
namespaces = {}
|
||||
if "_warnings" in self.dico:
|
||||
_warnings = self.dico.pop("_warnings")
|
||||
if self.export_warnings:
|
||||
|
|
@ -120,6 +122,8 @@ class RougailOutputAnsible(RougailOutputJson):
|
|||
host_name = hosts["prefix_name"] + index
|
||||
else:
|
||||
host_name = host
|
||||
if "namespaces" in hosts:
|
||||
namespaces[host] = hosts["namespaces"]
|
||||
ret_hosts.setdefault(name, {})[host_name] = host
|
||||
ret.setdefault(name, {}).setdefault("hosts", []).append(
|
||||
host_name
|
||||
|
|
@ -129,14 +133,21 @@ class RougailOutputAnsible(RougailOutputJson):
|
|||
for hosts in ret_hosts.values():
|
||||
for host, domain_name in hosts.items():
|
||||
ret["_meta"]["hostvars"][host] = {"ansible_host": domain_name}
|
||||
if self.namespace_is_hostname:
|
||||
host_namespace = normalize_family(host)
|
||||
if host_namespace in self.dico:
|
||||
ret["_meta"]["hostvars"][host].update(
|
||||
self.dico[host_namespace]
|
||||
)
|
||||
if self.no_namespace_in_vars:
|
||||
if host in namespaces:
|
||||
for namespace in namespaces[host]:
|
||||
if namespace in self.dico:
|
||||
ret["_meta"]["hostvars"][host].update(self.dico[namespace])
|
||||
else:
|
||||
for ns_vars in self.dico.values():
|
||||
ret["_meta"]["hostvars"][host].update(ns_vars)
|
||||
else:
|
||||
ret["_meta"]["hostvars"][host].update(self.dico)
|
||||
if host in namespaces:
|
||||
for namespace in namespaces[host]:
|
||||
if namespace in self.dico:
|
||||
ret["_meta"]["hostvars"][host][namespace] = self.dico[namespace]
|
||||
else:
|
||||
ret["_meta"]["hostvars"][host].update(self.dico)
|
||||
self.dico = ret
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ ansible:
|
|||
description: {_('Namespace with host values')}
|
||||
default: "hosts"
|
||||
|
||||
namespace_is_hostname:
|
||||
description: {_('Only variables in host namespace is available by a host')}
|
||||
no_namespace_in_vars:
|
||||
description: {_('Remove namespace name in host vars')}
|
||||
default: false
|
||||
|
||||
export_warnings:
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in a new issue