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 ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
|
|
||||||
|
|
@ -55,20 +55,26 @@ class RougailOutputAnsible(RougailOutputJson):
|
||||||
def manage_errors(self) -> bool:
|
def manage_errors(self) -> bool:
|
||||||
if not super().manage_errors():
|
if not super().manage_errors():
|
||||||
if not self.support_namespace:
|
if not self.support_namespace:
|
||||||
self.errors.append(_('no namespace configured'))
|
self.errors.append(_("no namespace configured"))
|
||||||
hosts_config = self.config.option('hosts')
|
hosts_config = self.config.option("hosts")
|
||||||
try:
|
try:
|
||||||
if hosts_config.group_type() != groups.namespace:
|
if hosts_config.group_type() != groups.namespace:
|
||||||
hosts_config = None
|
hosts_config = None
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
hosts_config = None
|
hosts_config = None
|
||||||
if not hosts_config:
|
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:
|
else:
|
||||||
try:
|
try:
|
||||||
hosts_config.option('hostnames').name()
|
hosts_config.option("hostnames").name()
|
||||||
except AttributeError:
|
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 super().manage_errors()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -85,53 +91,67 @@ class RougailOutputAnsible(RougailOutputJson):
|
||||||
|
|
||||||
def json_to_ansible(self):
|
def json_to_ansible(self):
|
||||||
ret = {"_meta": {"hostvars": {}}, "all": {"children": ["ungrouped"]}}
|
ret = {"_meta": {"hostvars": {}}, "all": {"children": ["ungrouped"]}}
|
||||||
if '_warnings' in self.dico:
|
if "_warnings" in self.dico:
|
||||||
ret["_meta"]["hostvars"]["localhost"] = {'_warnings': self.dico.pop('_warnings')}
|
ret["_meta"]["hostvars"]["localhost"] = {
|
||||||
|
"_warnings": self.dico.pop("_warnings")
|
||||||
|
}
|
||||||
ret["ungrouped"] = {"hosts": ["localhost"]}
|
ret["ungrouped"] = {"hosts": ["localhost"]}
|
||||||
if '_errors' in self.dico:
|
if "_errors" in self.dico:
|
||||||
ret["_meta"]["hostvars"].setdefault("localhost", {})['_errors'] = self.dico.pop('_errors')
|
ret["_meta"]["hostvars"].setdefault("localhost", {})["_errors"] = (
|
||||||
|
self.dico.pop("_errors")
|
||||||
|
)
|
||||||
if "ungrouped" not in ret:
|
if "ungrouped" not in ret:
|
||||||
ret["ungrouped"] = {"hosts": ["localhost"]}
|
ret["ungrouped"] = {"hosts": ["localhost"]}
|
||||||
if self.host_namespace in self.dico:
|
if self.host_namespace in self.dico:
|
||||||
hosts = self.dico.pop(self.host_namespace)
|
hosts = self.dico.pop(self.host_namespace)
|
||||||
if "hostnames" not in hosts:
|
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:
|
if "ungrouped" not in ret:
|
||||||
ret["ungrouped"] = {"hosts": ["localhost"]}
|
ret["ungrouped"] = {"hosts": ["localhost"]}
|
||||||
hostnames = {}
|
hostnames = {}
|
||||||
else:
|
else:
|
||||||
hostnames = hosts['hostnames']
|
hostnames = hosts["hostnames"]
|
||||||
ret_hosts = {}
|
ret_hosts = {}
|
||||||
for name, hosts in hostnames.items():
|
for name, hosts in hostnames.items():
|
||||||
if 'hosts' in hosts:
|
if "hosts" in hosts:
|
||||||
if 'prefix_name' in hosts:
|
if "prefix_name" in hosts:
|
||||||
host_name = hosts['prefix_name']
|
host_name = hosts["prefix_name"]
|
||||||
add_index = True
|
add_index = True
|
||||||
elif len(hosts["hosts"]) == 1:
|
elif len(hosts["hosts"]) == 1:
|
||||||
host_name = hosts["hosts"][0]
|
host_name = hosts["hosts"][0]
|
||||||
add_index = False
|
add_index = False
|
||||||
else:
|
else:
|
||||||
raise Exception("cannot find prefix_name")
|
raise Exception("cannot find prefix_name")
|
||||||
for idx, host in enumerate(hosts['hosts']):
|
for idx, host in enumerate(hosts["hosts"]):
|
||||||
index = str(idx + 1)
|
index = str(idx + 1)
|
||||||
if idx < 9:
|
if idx < 9:
|
||||||
index = '0' + index
|
index = "0" + index
|
||||||
if 'prefix_name' in hosts:
|
if "prefix_name" in hosts:
|
||||||
host_name = hosts['prefix_name'] + index
|
host_name = hosts["prefix_name"] + index
|
||||||
ret_hosts.setdefault(name, {})[host_name] = host
|
ret_hosts.setdefault(name, {})[host_name] = host
|
||||||
ret.setdefault(name, {}).setdefault('hosts', []).append(host_name)
|
ret.setdefault(name, {}).setdefault("hosts", []).append(
|
||||||
|
host_name
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
ret["all"]["children"].append(name)
|
ret["all"]["children"].append(name)
|
||||||
ret[name] = hosts
|
ret[name] = hosts
|
||||||
for hosts in ret_hosts.values():
|
for hosts in ret_hosts.values():
|
||||||
for host, domain_name in hosts.items():
|
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:
|
if self.namespace_is_hostname:
|
||||||
host_namespace = normalize_family(host)
|
host_namespace = normalize_family(host)
|
||||||
if host_namespace in self.dico:
|
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:
|
else:
|
||||||
ret['_meta']['hostvars'][host].update(self.dico)
|
ret["_meta"]["hostvars"][host].update(self.dico)
|
||||||
self.dico = ret
|
self.dico = ret
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ def get_rougail_config(
|
||||||
*,
|
*,
|
||||||
backward_compatibility=True,
|
backward_compatibility=True,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
options = [f"""
|
options = [
|
||||||
|
f"""
|
||||||
list:
|
list:
|
||||||
description: {_('parameter added only to be compatible with Ansible')}
|
description: {_('parameter added only to be compatible with Ansible')}
|
||||||
default: false
|
default: false
|
||||||
|
|
@ -44,7 +45,8 @@ json:
|
||||||
disabled
|
disabled
|
||||||
{{% endif %}}
|
{{% endif %}}
|
||||||
|
|
||||||
""", f"""
|
""",
|
||||||
|
f"""
|
||||||
ansible:
|
ansible:
|
||||||
exists: true
|
exists: true
|
||||||
redefine: true
|
redefine: true
|
||||||
|
|
@ -56,7 +58,8 @@ ansible:
|
||||||
disabled
|
disabled
|
||||||
{{% endif %}}
|
{{% endif %}}
|
||||||
|
|
||||||
""", f"""
|
""",
|
||||||
|
f"""
|
||||||
ansible:
|
ansible:
|
||||||
description: {_('Configuration of output Ansible')}
|
description: {_('Configuration of output Ansible')}
|
||||||
exists: false
|
exists: false
|
||||||
|
|
@ -65,7 +68,8 @@ ansible:
|
||||||
when_not: ansible
|
when_not: ansible
|
||||||
propertyerror: false
|
propertyerror: false
|
||||||
|
|
||||||
""", f"""
|
""",
|
||||||
|
f"""
|
||||||
ansible:
|
ansible:
|
||||||
|
|
||||||
host_namespace:
|
host_namespace:
|
||||||
|
|
@ -75,7 +79,8 @@ ansible:
|
||||||
namespace_is_hostname:
|
namespace_is_hostname:
|
||||||
description: {_('Only variables in host namespace is available by a host')}
|
description: {_('Only variables in host namespace is available by a host')}
|
||||||
default: false
|
default: false
|
||||||
"""]
|
""",
|
||||||
|
]
|
||||||
return {
|
return {
|
||||||
"name": "ansible",
|
"name": "ansible",
|
||||||
"process": "output",
|
"process": "output",
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
from gettext import translation
|
from gettext import translation
|
||||||
from pathlib import Path
|
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
|
_ = t.gettext
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue