Compare commits

...

2 Commits

2 changed files with 134 additions and 46 deletions

154
README.md
View File

@ -154,62 +154,150 @@ tri_variables->e
---
- hosts: module_test
tasks:
- name: Test if minimal config is already done
stat:
path: "/etc/eole/config.eol"
register: configeol
- name: Configuration minimale
creoleset:
variables:
- name: "numero_etab"
value: "0000000B"
- name: "libelle_etab"
value: "bbohard_etab"
- name: "nom_academie"
value: "bbohard"
- name: "nom_domaine_local"
value: "bbohard.lan"
- name: "eth0_method"
value: "dhcp"
- name: "ip_ssh_eth0"
value:
- "192.168.122.0"
- name: "netmask_ssh_eth0"
value:
- "255.255.255.0"
- name: "ip_admin_eth0"
value: "192.168.122.0"
- name: "netmask_admin_eth0"
value: "255.255.255.0"
- name: "activer_exim_relay_smtp"
value: "non"
- name: "nom_machine"
value: "{{ hostname }}"
when: not configeol.stat.exists
- name: Set some hostnames
creoleset:
variables:
- name: activer_ajout_hosts
value: oui
- name: nom_court_hosts
value:
- minio-a1
- minio-a2
- minio-b1
- minio-b2
- name: nom_long_hosts
value:
- minio-a1.cadoles.lan
- minio-a2.cadoles.lan
- minio-b1.cadoles.lan
- minio-b2.cadoles.lan
- name: adresse_ip_hosts
value:
- 10.10.0.1
- 10.10.0.2
- 10.10.0.3
- 10.10.0.4
- name: Configuration dune variable isolée simple
creoleset:
variables:
- name: "libelle_etab"
value: "etab_test"
- name: "libelle_etab"
value: "etab_test"
- name: Configuration dune variable isolée multi
creoleset:
variables:
- name: "adresse_ip_dns"
value:
- "192.168.0.1"
- "192.168.232.2"
- name: "adresse_ip_dns"
value:
- "1.1.1.1"
- "8.8.8.8"
- name: Configuration dun groupe de variables
creoleset:
variables:
- name: "ip_ssh_eth0"
value:
- "192.168.0.0"
- name: "netmask_ssh_eth0"
value:
- "255.255.0.0"
- name: "ip_ssh_eth0"
value:
- "192.168.0.0"
- name: "netmask_ssh_eth0"
value:
- "255.255.0.0"
- name: Debug
shell:
cmd: "CreoleGet ip_ssh_eth0"
- name: Configuration avec variable nécessitant activation
creoleset:
variables:
- name: "additional_repository_name"
value: "Cadoles unstable"
- name: "additional_repository_source"
value: "deb https://vulcain.cadoles.com 2.7.2-unstable main"
- name: "additional_repository_key_type"
value: "URL de la clé"
- name: "additional_repository_key_url"
value: "https://vulcain.cadoles.com/cadoles.gpg"
- name: "additional_repository_name"
value: "Cadoles unstable"
- name: "additional_repository_source"
value: "deb https://vulcain.cadoles.com 2.7.0-unstable main"
- name: "additional_repository_key_type"
value: "URL de la clé"
- name: "additional_repository_key_url"
value: "https://vulcain.cadoles.com/cadoles.gpg"
state: present
- name: Configuration ajoutée
creoleset:
variables:
- name: "ip_ssh_eth0"
value: "10.253.30.0"
- name: "netmask_ssh_eth0"
value: "255.255.255.0"
state: present
- name: 'additional_repository_name'
value: 'mariadb'
- name: 'additional_repository_source'
value: 'deb http://mariadb.mirrors.ovh.net/MariaDB/repo/10.3/ubuntu bionic main'
- name: 'additional_repository_key_type'
value: 'serveur de clés'
- name: 'additional_repository_key_signserver'
value: 'hkp://keyserver.ubuntu.com:80'
- name: 'additional_repository_key_fingerprint'
value: 'F1656F24C74CD1D8'
state: present
- name: Configuration vidée
creoleset:
variables:
- name: 'additional_repository_name'
value: []
- name: 'additional_repository_source'
value: []
- name: 'additional_repository_key_type'
value: []
- name: 'additional_repository_key_fingerprint'
value: []
- name: 'additional_repository_key_url'
value: []
- name: Configuration ajoutée
creoleset:
variables:
- name: "ip_ssh_eth0"
value: "10.253.30.0"
- name: "netmask_ssh_eth0"
value: "255.255.255.0"
state: present
- name: idempotence
creoleset:
variables:
- name: "ip_ssh_eth0"
value:
- "192.168.0.0"
- "10.253.30.0"
- name: "netmask_ssh_eth0"
value:
- "255.255.0.0"
- "255.255.255.0"
- name: "ip_ssh_eth0"
value:
- "192.168.0.0"
- "10.10.0.0"
- name: "netmask_ssh_eth0"
value:
- "255.255.0.0"
- "255.255.255.0"
```
### zephir_register

View File

@ -75,7 +75,7 @@ class ExpectationCollection:
def add_expectation(self, expectation):
if expectation.get_pattern() in self.expectations_lookup:
if expectation.context in [exp.context for exp in self.expectations_lookup[expectation.get_pattern()]]:
print(f'Can not add {expectation} to collection')
print('Can not add {} to collection'.format(expectation))
return False
self.expectations_lookup[expectation.get_pattern()] = self.expectations_lookup.setdefault(expectation.get_pattern(), []) + [expectation]
return True
@ -123,7 +123,7 @@ class Expectation:
self.next = {}
def get_pattern(self, previous_answer=None):
return re.compile(f'(.*){re.escape(self.pattern.format(variable=previous_answer))}(.*)')
return re.compile(r'(.*){}(.*)'.format(re.escape(self.pattern.format(variable=previous_answer))))
def set_next_expectation(self, expectation, triggers=None):
if not isinstance(triggers, list):
@ -132,19 +132,19 @@ class Expectation:
self.next[trigger] = expectation
def set_response(self, response):
print(f'Setting {response} for {self.pattern}')
print('Setting {} for {}'.format(response, self.pattern))
self.response = response
def expect(self, spawned, previous_answer=None):
print(f'-> expecting next "{self.pattern.format(variable=previous_answer)}"')
print('-> expecting next "{}"'.format(self.pattern.format(variable=previous_answer)))
p = spawned.expect([pexpect.EOF, pexpect.TIMEOUT, self.get_pattern(previous_answer=previous_answer)])
if p not in [0, 1]:
self.answer(spawned)
else:
print(f'-> before: {spawned.before}\n-> after: {spawned.after}\n-> {self.pattern}')
print('-> before: {}\n-> after: {}\n-> {}'.format(spawned.before, spawned_after, self.pattern))
def answer(self, spawned):
print(f'-> answering "{self.response}" to "{spawned.after}"')
print('-> answering "{}" to "{}"'.format(self.response, spawned.after))
if self.response is not None:
spawned.sendline(self.response)
if self.response in self.next:
@ -309,17 +309,17 @@ def run_module():
result['module'] = module.params["module"]
if module.params.get('variables', None) and not set(module.params['variables'].keys()).issubset(set(expectations.get_exposed_expectation_names())):
unknown_variables = list(set(module.params['variables'].keys()).difference(set(expectations.get_exposed_expectation_names())))
result['msg'] += f"Variables {unknown_variables} not available\n"
result['msg'] += "Variables {} not available\n".format(unknown_variables)
else:
for variable in module.params.get('variables', {}).keys():
result['msg'] += f"Overloading variable {variable}\n"
result['msg'] += "Overloading variable {}\n".format(variable)
else:
result['msg'] += f'Module {module.module} not supported\n'
result['msg'] += 'Module {} not supported\n'.format(module.module)
module.exit_json(**result)
if module.params['module'] not in supported_modules:
result['msg'] += f"Unsupported module {module.params['module']}\n"
result['msg'] += "Unsupported module {}\n".format(module.params['module'])
module.fail_json(**result)
else:
result['module'] = module.params['module']
@ -327,7 +327,7 @@ def run_module():
if module.params.get('variables', None):
if not set(module.params['variables'].keys()).issubset(set(expectations.get_exposed_expectation_names())):
unknown_variables = list(set(module.params['variables'].keys()).difference(set(expectations.get_exposed_expectation_names())))
result['msg'] += f"Variables {unknown_variables} not available\n"
result['msg'] += "Variables {} not available\n".format(unknown_variables)
module.fail_json(**result)
else:
for expectation_name, response in module.params['variables'].items():
@ -342,7 +342,7 @@ def run_module():
if p == 0:
break
if p == 1:
print(f'Some missing expectations for {instance_process.before}{instance_process.after}')
print('Some missing expectations for {}{}'.format(instance_process.before, instance_process.after))
break
pattern = patterns[p]
for expectation in expectations.get_expectations_by_pattern(patterns[p]):
@ -351,7 +351,7 @@ def run_module():
break
some_index += 1
result['changed'] = True
result['msg'] += f"Module {result['module']} instanciated"
result['msg'] += "Module {} instanciated".format(result['module'])
module.exit_json(**result)
except Exception as err:
result['msg'] += err