Compare commits
No commits in common. "48f403f2b27db52d5a5511bd33345f3d362fd7ef" and "deefccbd4c122d74a080cc819ddcf5b829d5f1dd" have entirely different histories.
48f403f2b2
...
deefccbd4c
9 changed files with 5 additions and 168 deletions
|
|
@ -1,9 +1,3 @@
|
||||||
## 0.2.0a21 (2026-01-09)
|
|
||||||
|
|
||||||
### Feat
|
|
||||||
|
|
||||||
- add vars for an specified host
|
|
||||||
|
|
||||||
## 0.2.0a20 (2025-12-30)
|
## 0.2.0a20 (2025-12-30)
|
||||||
|
|
||||||
### Feat
|
### Feat
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ requires = ["flit_core >=3.8.0,<4"]
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "rougail.output_ansible"
|
name = "rougail.output_ansible"
|
||||||
version = "0.2.0a21"
|
version = "0.2.0a20"
|
||||||
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"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Silique (https://www.silique.fr)
|
Silique (https://www.silique.fr)
|
||||||
Copyright (C) 2022-2026
|
Copyright (C) 2022-2025
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU Lesser General Public License as published by the
|
under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
|
@ -91,7 +91,6 @@ class RougailOutputAnsible(RougailOutputJson):
|
||||||
def json_to_ansible(self):
|
def json_to_ansible(self):
|
||||||
ret = {"_meta": {"hostvars": {}}}
|
ret = {"_meta": {"hostvars": {}}}
|
||||||
namespaces = {}
|
namespaces = {}
|
||||||
extra_vars = {}
|
|
||||||
if "_warnings" in self.dico:
|
if "_warnings" in self.dico:
|
||||||
_warnings = self.dico.pop("_warnings")
|
_warnings = self.dico.pop("_warnings")
|
||||||
if self.export_warnings:
|
if self.export_warnings:
|
||||||
|
|
@ -124,10 +123,6 @@ class RougailOutputAnsible(RougailOutputJson):
|
||||||
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 "vars" in hosts and "all" in hosts["vars"]:
|
|
||||||
current_extra_vars = hosts["vars"]["all"]
|
|
||||||
else:
|
|
||||||
current_extra_vars = {}
|
|
||||||
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:
|
||||||
|
|
@ -142,11 +137,6 @@ class RougailOutputAnsible(RougailOutputJson):
|
||||||
ret.setdefault(name, {}).setdefault("hosts", []).append(
|
ret.setdefault(name, {}).setdefault("hosts", []).append(
|
||||||
host_name
|
host_name
|
||||||
)
|
)
|
||||||
if "vars" in hosts and str(idx) in hosts["vars"]:
|
|
||||||
extra_vars[host_name] = current_extra_vars.copy()
|
|
||||||
extra_vars[host_name].update(hosts["vars"][str(idx)])
|
|
||||||
elif current_extra_vars:
|
|
||||||
extra_vars[host_name] = current_extra_vars
|
|
||||||
else:
|
else:
|
||||||
ret[name] = hosts
|
ret[name] = hosts
|
||||||
# manage hostsnames and vars in hostsname
|
# manage hostsnames and vars in hostsname
|
||||||
|
|
@ -168,8 +158,6 @@ class RougailOutputAnsible(RougailOutputJson):
|
||||||
ret["_meta"]["hostvars"][host][namespace] = self.dico[namespace]
|
ret["_meta"]["hostvars"][host][namespace] = self.dico[namespace]
|
||||||
else:
|
else:
|
||||||
ret["_meta"]["hostvars"][host].update(self.dico)
|
ret["_meta"]["hostvars"][host].update(self.dico)
|
||||||
if host in extra_vars:
|
|
||||||
ret["_meta"]["hostvars"][host].update(extra_vars[host])
|
|
||||||
# manage hostnames define with tag ansible_host and add groups
|
# manage hostnames define with tag ansible_host and add groups
|
||||||
for namespace, hosts in self.hosts.items():
|
for namespace, hosts in self.hosts.items():
|
||||||
if namespace not in ret:
|
if namespace not in ret:
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
__version__ = "0.2.0a21"
|
__version__ = "0.2.0a20"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Silique (https://www.silique.fr)
|
Silique (https://www.silique.fr)
|
||||||
Copyright (C) 2024-2026
|
Copyright (C) 2024-2025
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU Lesser General Public License as published by the
|
under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""Internationalisation utilities
|
"""Internationalisation utilities
|
||||||
Silique (https://www.silique.fr)
|
Silique (https://www.silique.fr)
|
||||||
Copyright (C) 2024-2026
|
Copyright (C) 2024-2025
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU Lesser General Public License as published by the
|
under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
---
|
|
||||||
version: "1.1"
|
|
||||||
|
|
||||||
hostnames:
|
|
||||||
|
|
||||||
group1:
|
|
||||||
|
|
||||||
hosts:
|
|
||||||
type: domainname
|
|
||||||
multi: true
|
|
||||||
default:
|
|
||||||
- group1.net
|
|
||||||
|
|
||||||
prefix_name:
|
|
||||||
default: GROUP1_
|
|
||||||
|
|
||||||
group2:
|
|
||||||
|
|
||||||
hosts:
|
|
||||||
type: domainname
|
|
||||||
multi: true
|
|
||||||
default:
|
|
||||||
- group2.net
|
|
||||||
- group3.net
|
|
||||||
|
|
||||||
prefix_name:
|
|
||||||
default: GROUP2_
|
|
||||||
|
|
||||||
vars:
|
|
||||||
|
|
||||||
all:
|
|
||||||
|
|
||||||
added_var1: true
|
|
||||||
|
|
||||||
a_family:
|
|
||||||
|
|
||||||
with_a_variable: 1
|
|
||||||
|
|
||||||
"0":
|
|
||||||
|
|
||||||
added_var2: true
|
|
||||||
|
|
||||||
group3:
|
|
||||||
|
|
||||||
hosts:
|
|
||||||
type: domainname
|
|
||||||
multi: true
|
|
||||||
default:
|
|
||||||
- group4.net
|
|
||||||
- group5.net
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
---
|
|
||||||
version: "1.1"
|
|
||||||
|
|
||||||
hostnames:
|
|
||||||
|
|
||||||
groups:
|
|
||||||
children:
|
|
||||||
multi: true
|
|
||||||
default:
|
|
||||||
- group1
|
|
||||||
- group2
|
|
||||||
|
|
@ -280,87 +280,3 @@ def test_no_warnings():
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_host_with_vars():
|
|
||||||
rougailconfig = get_rougail_config(Path('tests/warnings/structures'), True)
|
|
||||||
##################################
|
|
||||||
rougailconfig['step.output'] = 'ansible'
|
|
||||||
rougailconfig['ansible.export_warnings'] = False
|
|
||||||
rougailconfig['step.user_data'] = ['yaml']
|
|
||||||
rougailconfig['yaml.filename'] = ['tests/warnings/yaml/config.yml']
|
|
||||||
extra_namespaces = rougailconfig["extra_namespaces"]
|
|
||||||
extra_namespaces["hosts"] = [str(Path(__file__).parent / "hosts-with-vars")]
|
|
||||||
rougailconfig['extra_namespaces'] = extra_namespaces
|
|
||||||
##################################
|
|
||||||
rougail = Rougail(rougailconfig)
|
|
||||||
config = rougail.run()
|
|
||||||
generated_user_data = RougailUserDataYaml(config, rougailconfig=rougailconfig).run()
|
|
||||||
err_warn = rougail.user_data(generated_user_data)
|
|
||||||
output = RougailOutput(
|
|
||||||
config=config,
|
|
||||||
rougailconfig=rougailconfig,
|
|
||||||
user_data_errors=err_warn["errors"],
|
|
||||||
user_data_warnings=err_warn["warnings"],
|
|
||||||
)
|
|
||||||
ret = output.run()
|
|
||||||
assert ret[0] is True
|
|
||||||
assert safe_load(ret[1]) == {
|
|
||||||
"_meta": {
|
|
||||||
"hostvars": {
|
|
||||||
"GROUP1_01": {
|
|
||||||
"ansible_host": "group1.net",
|
|
||||||
"rougail": {
|
|
||||||
"a_var": "a_value"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"GROUP2_01": {
|
|
||||||
"ansible_host": "group2.net",
|
|
||||||
'rougail': {
|
|
||||||
'a_var': 'a_value',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'GROUP2_02': {
|
|
||||||
'ansible_host': 'group3.net',
|
|
||||||
'rougail': {
|
|
||||||
'a_var': 'a_value',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'group4.net': {
|
|
||||||
'ansible_host': 'group4.net',
|
|
||||||
'rougail': {
|
|
||||||
'a_var': 'a_value',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'group5.net': {
|
|
||||||
'ansible_host': 'group5.net',
|
|
||||||
"rougail": {
|
|
||||||
"a_var": "a_value"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'group1': {
|
|
||||||
'hosts': [
|
|
||||||
'GROUP1_01',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'group2': {
|
|
||||||
'hosts': [
|
|
||||||
'GROUP2_01',
|
|
||||||
'GROUP2_02',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'group3': {
|
|
||||||
'hosts': [
|
|
||||||
'group4.net',
|
|
||||||
'group5.net',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'groups': {
|
|
||||||
'children': [
|
|
||||||
'group1',
|
|
||||||
'group2',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue