fix: black
This commit is contained in:
parent
de3c6b8db6
commit
3173cf3d5c
4 changed files with 56 additions and 29 deletions
|
|
@ -5,7 +5,7 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"POT-Creation-Date: 2025-04-29 23:02+0200\n"
|
||||
"POT-Creation-Date: 2025-05-03 22:46+0200\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"
|
||||
|
|
|
|||
|
|
@ -55,20 +55,26 @@ class RougailOutputAnsible(RougailOutputJson):
|
|||
def manage_errors(self) -> bool:
|
||||
if not super().manage_errors():
|
||||
if not self.support_namespace:
|
||||
self.errors.append(_('no namespace configured'))
|
||||
hosts_config = self.config.option('hosts')
|
||||
self.errors.append(_("no namespace configured"))
|
||||
hosts_config = self.config.option("hosts")
|
||||
try:
|
||||
if hosts_config.group_type() != groups.namespace:
|
||||
hosts_config = None
|
||||
except AttributeError:
|
||||
hosts_config = None
|
||||
if not hosts_config:
|
||||
self.errors.append(_('cannot find host namespace "{0}"').format(self.host_namespace))
|
||||
self.errors.append(
|
||||
_('cannot find host namespace "{0}"').format(self.host_namespace)
|
||||
)
|
||||
else:
|
||||
try:
|
||||
hosts_config.option('hostnames').name()
|
||||
hosts_config.option("hostnames").name()
|
||||
except AttributeError:
|
||||
self.errors.append(_('malformated host namespace "{0}", should have the "hostnames" key').format(self.host_namespace))
|
||||
self.errors.append(
|
||||
_(
|
||||
'malformated host namespace "{0}", should have the "hostnames" key'
|
||||
).format(self.host_namespace)
|
||||
)
|
||||
return super().manage_errors()
|
||||
return True
|
||||
|
||||
|
|
@ -85,53 +91,67 @@ class RougailOutputAnsible(RougailOutputJson):
|
|||
|
||||
def json_to_ansible(self):
|
||||
ret = {"_meta": {"hostvars": {}}, "all": {"children": ["ungrouped"]}}
|
||||
if '_warnings' in self.dico:
|
||||
ret["_meta"]["hostvars"]["localhost"] = {'_warnings': self.dico.pop('_warnings')}
|
||||
if "_warnings" in self.dico:
|
||||
ret["_meta"]["hostvars"]["localhost"] = {
|
||||
"_warnings": self.dico.pop("_warnings")
|
||||
}
|
||||
ret["ungrouped"] = {"hosts": ["localhost"]}
|
||||
if '_errors' in self.dico:
|
||||
ret["_meta"]["hostvars"].setdefault("localhost", {})['_errors'] = self.dico.pop('_errors')
|
||||
if "_errors" in self.dico:
|
||||
ret["_meta"]["hostvars"].setdefault("localhost", {})["_errors"] = (
|
||||
self.dico.pop("_errors")
|
||||
)
|
||||
if "ungrouped" not in ret:
|
||||
ret["ungrouped"] = {"hosts": ["localhost"]}
|
||||
if self.host_namespace in self.dico:
|
||||
hosts = self.dico.pop(self.host_namespace)
|
||||
if "hostnames" not in hosts:
|
||||
ret["_meta"]["hostvars"].setdefault("localhost", {}).setdefault('_errors', []).append(_('cannot find "hostnames" in "{0}" namespace').format(self.host_namespace))
|
||||
ret["_meta"]["hostvars"].setdefault("localhost", {}).setdefault(
|
||||
"_errors", []
|
||||
).append(
|
||||
_('cannot find "hostnames" in "{0}" namespace').format(
|
||||
self.host_namespace
|
||||
)
|
||||
)
|
||||
if "ungrouped" not in ret:
|
||||
ret["ungrouped"] = {"hosts": ["localhost"]}
|
||||
hostnames = {}
|
||||
else:
|
||||
hostnames = hosts['hostnames']
|
||||
hostnames = hosts["hostnames"]
|
||||
ret_hosts = {}
|
||||
for name, hosts in hostnames.items():
|
||||
if 'hosts' in hosts:
|
||||
if 'prefix_name' in hosts:
|
||||
host_name = hosts['prefix_name']
|
||||
if "hosts" in hosts:
|
||||
if "prefix_name" in hosts:
|
||||
host_name = hosts["prefix_name"]
|
||||
add_index = True
|
||||
elif len(hosts["hosts"]) == 1:
|
||||
host_name = hosts["hosts"][0]
|
||||
add_index = False
|
||||
else:
|
||||
raise Exception("cannot find prefix_name")
|
||||
for idx, host in enumerate(hosts['hosts']):
|
||||
for idx, host in enumerate(hosts["hosts"]):
|
||||
index = str(idx + 1)
|
||||
if idx < 9:
|
||||
index = '0' + index
|
||||
if 'prefix_name' in hosts:
|
||||
host_name = hosts['prefix_name'] + index
|
||||
index = "0" + index
|
||||
if "prefix_name" in hosts:
|
||||
host_name = hosts["prefix_name"] + index
|
||||
ret_hosts.setdefault(name, {})[host_name] = host
|
||||
ret.setdefault(name, {}).setdefault('hosts', []).append(host_name)
|
||||
ret.setdefault(name, {}).setdefault("hosts", []).append(
|
||||
host_name
|
||||
)
|
||||
else:
|
||||
ret["all"]["children"].append(name)
|
||||
ret[name] = hosts
|
||||
for hosts in ret_hosts.values():
|
||||
for host, domain_name in hosts.items():
|
||||
ret['_meta']['hostvars'][host] = {'ansible_host': domain_name}
|
||||
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])
|
||||
ret["_meta"]["hostvars"][host].update(
|
||||
self.dico[host_namespace]
|
||||
)
|
||||
else:
|
||||
ret['_meta']['hostvars'][host].update(self.dico)
|
||||
ret["_meta"]["hostvars"][host].update(self.dico)
|
||||
self.dico = ret
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ def get_rougail_config(
|
|||
*,
|
||||
backward_compatibility=True,
|
||||
) -> dict:
|
||||
options = [f"""
|
||||
options = [
|
||||
f"""
|
||||
list:
|
||||
description: {_('parameter added only to be compatible with Ansible')}
|
||||
default: false
|
||||
|
|
@ -44,7 +45,8 @@ json:
|
|||
disabled
|
||||
{{% endif %}}
|
||||
|
||||
""", f"""
|
||||
""",
|
||||
f"""
|
||||
ansible:
|
||||
exists: true
|
||||
redefine: true
|
||||
|
|
@ -56,7 +58,8 @@ ansible:
|
|||
disabled
|
||||
{{% endif %}}
|
||||
|
||||
""", f"""
|
||||
""",
|
||||
f"""
|
||||
ansible:
|
||||
description: {_('Configuration of output Ansible')}
|
||||
exists: false
|
||||
|
|
@ -65,7 +68,8 @@ ansible:
|
|||
when_not: ansible
|
||||
propertyerror: false
|
||||
|
||||
""", f"""
|
||||
""",
|
||||
f"""
|
||||
ansible:
|
||||
|
||||
host_namespace:
|
||||
|
|
@ -75,7 +79,8 @@ ansible:
|
|||
namespace_is_hostname:
|
||||
description: {_('Only variables in host namespace is available by a host')}
|
||||
default: false
|
||||
"""]
|
||||
""",
|
||||
]
|
||||
return {
|
||||
"name": "ansible",
|
||||
"process": "output",
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
from gettext import translation
|
||||
from pathlib import Path
|
||||
|
||||
t = translation("rougail_output_ansible", str(Path(__file__).parent / "locale"), fallback=True)
|
||||
t = translation(
|
||||
"rougail_output_ansible", str(Path(__file__).parent / "locale"), fallback=True
|
||||
)
|
||||
|
||||
_ = t.gettext
|
||||
|
|
|
|||
Loading…
Reference in a new issue