Compare commits
No commits in common. "0.1.1a2" and "main" have entirely different histories.
11 changed files with 29 additions and 54 deletions
13
CHANGELOG.md
13
CHANGELOG.md
|
|
@ -1,13 +0,0 @@
|
||||||
## 0.1.1a2 (2024-11-29)
|
|
||||||
|
|
||||||
## 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.1a2"
|
version = "0.1.0"
|
||||||
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,7 +19,6 @@ 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
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,39 +43,39 @@ class RougailOutputAnsible(RougailOutputJson):
|
||||||
self.errors = []
|
self.errors = []
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
|
|
||||||
def exporter(self) -> None:
|
def run(self) -> None:
|
||||||
super().exporter()
|
self.exporter()
|
||||||
self.json_to_ansible()
|
print(dumps(self.json_to_ansible(), ensure_ascii=False, indent=2))
|
||||||
|
|
||||||
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))
|
||||||
elif 'hostnames' not in self.dico[self.host_namespace]:
|
if '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))
|
||||||
if self.errors:
|
ret = {"_meta": {"hostvars": {}}, "all": {"children": ["ungrouped"]}}
|
||||||
ret["_meta"]["hostvars"]["localhost"] = {'_errors': self.errors}
|
# if self.errors:
|
||||||
ret["ungrouped"] = {"hosts": ["localhost"]}
|
# ret["_meta"]["hostvars"]["localhost"] = {'_errors': self.errors}
|
||||||
else:
|
# ret["ungrouped"] = {"hosts": ["localhost"]}
|
||||||
hostnames = self.dico[self.host_namespace]['hostnames']
|
# else:
|
||||||
ret_hosts = {}
|
hostnames = self.dico[self.host_namespace]['hostnames']
|
||||||
for name, hosts in hostnames.items():
|
ret_hosts = {}
|
||||||
if 'hosts' in hosts:
|
for name, hosts in hostnames.items():
|
||||||
for idx, host in enumerate(hosts['hosts']):
|
if 'hosts' in hosts:
|
||||||
index = str(idx + 1)
|
for idx, host in enumerate(hosts['hosts']):
|
||||||
if idx < 9:
|
index = str(idx + 1)
|
||||||
index = '0' + index
|
if idx < 9:
|
||||||
host_name = hosts['prefix_name'] + index
|
index = '0' + index
|
||||||
ret_hosts.setdefault(name, {})[host_name] = host
|
host_name = hosts['prefix_name'] + index
|
||||||
ret.setdefault(name, {}).setdefault('hosts', []).append(host_name)
|
ret_hosts.setdefault(name, {})[host_name] = host
|
||||||
else:
|
ret.setdefault(name, {}).setdefault('hosts', []).append(host_name)
|
||||||
ret["all"]["children"].append(name)
|
else:
|
||||||
ret[name] = hosts
|
ret["all"]["children"].append(name)
|
||||||
for hosts in ret_hosts.values():
|
ret[name] = hosts
|
||||||
for host, domain_name in hosts.items():
|
for hosts in ret_hosts.values():
|
||||||
ret['_meta']['hostvars'][host] = {'ansible_host': domain_name}
|
for host, domain_name in hosts.items():
|
||||||
ret['_meta']['hostvars'][host].update(self.dico)
|
ret['_meta']['hostvars'][host] = {'ansible_host': domain_name}
|
||||||
self.dico = ret
|
ret['_meta']['hostvars'][host].update(self.dico)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
RougailOutput = RougailOutputAnsible
|
RougailOutput = RougailOutputAnsible
|
||||||
|
|
|
||||||
BIN
src/rougail/output_ansible/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
src/rougail/output_ansible/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/rougail/output_ansible/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
src/rougail/output_ansible/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
src/rougail/output_ansible/__pycache__/cli.cpython-312.pyc
Normal file
BIN
src/rougail/output_ansible/__pycache__/cli.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/rougail/output_ansible/__pycache__/config.cpython-312.pyc
Normal file
BIN
src/rougail/output_ansible/__pycache__/config.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/rougail/output_ansible/__pycache__/config.cpython-313.pyc
Normal file
BIN
src/rougail/output_ansible/__pycache__/config.cpython-313.pyc
Normal file
Binary file not shown.
BIN
src/rougail/output_ansible/__pycache__/i18n.cpython-313.pyc
Normal file
BIN
src/rougail/output_ansible/__pycache__/i18n.cpython-313.pyc
Normal file
Binary file not shown.
BIN
src/rougail/output_ansible/__pycache__/utils.cpython-312.pyc
Normal file
BIN
src/rougail/output_ansible/__pycache__/utils.cpython-312.pyc
Normal file
Binary file not shown.
|
|
@ -24,17 +24,6 @@ def get_rougail_config(
|
||||||
backward_compatibility=True,
|
backward_compatibility=True,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
options = """
|
options = """
|
||||||
list:
|
|
||||||
description: parameter added only to be compatible with Ansible
|
|
||||||
negative_description: parameter added only to be compatible with Ansible
|
|
||||||
default: false
|
|
||||||
disabled:
|
|
||||||
type: jinja
|
|
||||||
jinja: |
|
|
||||||
{% if step.output != 'ansible' %}
|
|
||||||
disabled
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
ansible:
|
ansible:
|
||||||
description: Configuration of output Ansible
|
description: Configuration of output Ansible
|
||||||
disabled:
|
disabled:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue