Compare commits
No commits in common. "main" and "0.1.1a1" have entirely different histories.
10 changed files with 41 additions and 29 deletions
11
CHANGELOG.md
Normal file
11
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
## 0.1.1a1 (2024-11-28)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- better errors support
|
||||||
|
|
||||||
|
## 0.1.1a0 (2024-11-27)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- first commit
|
||||||
|
|
@ -4,7 +4,7 @@ requires = ["flit_core >=3.8.0,<4"]
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "rougail.output_ansible"
|
name = "rougail.output_ansible"
|
||||||
version = "0.1.0"
|
version = "0.1.1a1"
|
||||||
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
|
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
description = "Rougail output ansible"
|
description = "Rougail output ansible"
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from json import dumps
|
from json import dumps
|
||||||
|
|
||||||
|
from .i18n import _
|
||||||
from ..output_json import RougailOutputJson
|
from ..output_json import RougailOutputJson
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -43,39 +44,39 @@ class RougailOutputAnsible(RougailOutputJson):
|
||||||
self.errors = []
|
self.errors = []
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
|
|
||||||
def run(self) -> None:
|
def exporter(self) -> None:
|
||||||
self.exporter()
|
super().exporter()
|
||||||
print(dumps(self.json_to_ansible(), ensure_ascii=False, indent=2))
|
self.json_to_ansible()
|
||||||
|
|
||||||
def json_to_ansible(self):
|
def json_to_ansible(self):
|
||||||
|
ret = {"_meta": {"hostvars": {}}, "all": {"children": ["ungrouped"]}}
|
||||||
if self.host_namespace not in self.dico:
|
if self.host_namespace not in self.dico:
|
||||||
self.errors.append(_('cannot find hosts namespace "{0}"').format(self.host_namespace))
|
self.errors.append(_('cannot find hosts namespace "{0}"').format(self.host_namespace))
|
||||||
if 'hostnames' not in self.dico[self.host_namespace]:
|
elif 'hostnames' not in self.dico[self.host_namespace]:
|
||||||
self.errors.append(_('malformated hosts namespace "{0}", should has "hostnames"').format(self.host_namespace))
|
self.errors.append(_('malformated hosts namespace "{0}", should has "hostnames"').format(self.host_namespace))
|
||||||
ret = {"_meta": {"hostvars": {}}, "all": {"children": ["ungrouped"]}}
|
if self.errors:
|
||||||
# if self.errors:
|
ret["_meta"]["hostvars"]["localhost"] = {'_errors': self.errors}
|
||||||
# ret["_meta"]["hostvars"]["localhost"] = {'_errors': self.errors}
|
ret["ungrouped"] = {"hosts": ["localhost"]}
|
||||||
# ret["ungrouped"] = {"hosts": ["localhost"]}
|
else:
|
||||||
# else:
|
hostnames = self.dico[self.host_namespace]['hostnames']
|
||||||
hostnames = self.dico[self.host_namespace]['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:
|
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
|
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}
|
ret['_meta']['hostvars'][host].update(self.dico)
|
||||||
ret['_meta']['hostvars'][host].update(self.dico)
|
self.dico = ret
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
RougailOutput = RougailOutputAnsible
|
RougailOutput = RougailOutputAnsible
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue