Compare commits

..

No commits in common. "14a2cc65f91d858a920e1dd1f09283aa70529443" and "30a605a81cf85c752fff66ad60acb2302ca09051" have entirely different histories.

9 changed files with 58 additions and 122 deletions

View file

@ -30,15 +30,6 @@ def fileslist(data, is_host=False, name_only=False, prefix=None):
prefix, prefix,
) )
for service, service_data in data.items(): for service, service_data in data.items():
if not service_data['activate']:
if service_data['engine'] == 'none' and service_data['type'] == 'service' and not 'overrides' in service_data:
_add(files,
{'owner': 'root', 'group': 'root', 'mode': '0755'},
base_systemd + '/systemd/system/' + service_data['doc'],
name_only,
prefix,
)
else:
if service_data['activate'] and service_data['engine'] != 'none': if service_data['activate'] and service_data['engine'] != 'none':
_add(files, _add(files,
{'owner': 'root', 'group': 'root', 'mode': '0755'}, {'owner': 'root', 'group': 'root', 'mode': '0755'},

View file

@ -99,7 +99,6 @@ class RisottoInventory(object):
continue continue
ret[server_name] = engine.rougail_variables_dict ret[server_name] = engine.rougail_variables_dict
ret['modules'] = {module_name: module_info['infos'].depends for module_name, module_info in module_infos.items() if module_name in modules} ret['modules'] = {module_name: module_info['infos'].depends for module_name, module_info in module_infos.items() if module_name in modules}
ret['delete_old_image'] = False
ret['configure_host'] = True ret['configure_host'] = True
ret['only_machine'] = None ret['only_machine'] = None
return dumps(ret, cls=RougailEncoder) return dumps(ret, cls=RougailEncoder)

View file

@ -4,7 +4,6 @@ from time import sleep
from os import fdopen from os import fdopen
from dbus import SystemBus, Array from dbus import SystemBus, Array
from dbus.exceptions import DBusException from dbus.exceptions import DBusException
from subprocess import run
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -142,13 +141,6 @@ def start(bus, machines):
errors.append(f'{host}: ' + '\n'.join(ret)) errors.append(f'{host}: ' + '\n'.join(ret))
return changed, errors return changed, errors
def enable(machines):
cmd = ['/usr/bin/machinectl', 'enable'] + machines
run(cmd)
return True
def run_module(): def run_module():
# define available arguments/parameters a user can pass to the module # define available arguments/parameters a user can pass to the module
module_args = dict( module_args = dict(
@ -180,23 +172,21 @@ def run_module():
if module.check_mode: if module.check_mode:
module.exit_json(**result) module.exit_json(**result)
bus = SystemBus()
# manipulate or modify the state as needed (this is going to be the # manipulate or modify the state as needed (this is going to be the
# part where your module will do what it needs to do) # part where your module will do what it needs to do)
machines = module.params['machines'] machines = module.params['machines']
if module.params['state'] == 'stopped': if module.params['state'] == 'stopped':
bus = SystemBus()
result['changed'], errors = stop(bus, machines) result['changed'], errors = stop(bus, machines)
if errors: if errors:
errors = '\n\n'.join(errors) errors = '\n\n'.join(errors)
module.fail_json(msg=f'Some machines are not stopping correctly {errors}', **result) module.fail_json(msg=f'Some machines are not stopping correctly {errors}', **result)
elif module.params['state'] == 'started': elif module.params['state'] == 'started':
bus = SystemBus()
result['changed'], errors = start(bus, machines) result['changed'], errors = start(bus, machines)
if errors: if errors:
errors = '\n\n'.join(errors) errors = '\n\n'.join(errors)
module.fail_json(msg=f'Some machines are not running correctly {errors}', **result) module.fail_json(msg=f'Some machines are not running correctly {errors}', **result)
elif module.params['state'] == 'enabled':
result['changed'] = enable(machines)
else: else:
module.fail_json(msg=f"Unknown state: {module.params['state']}") module.fail_json(msg=f"Unknown state: {module.params['state']}")

View file

@ -17,7 +17,6 @@
path: "installations{{ file.name }}" path: "installations{{ file.name }}"
checksum: sha256 checksum: sha256
get_checksum: yes get_checksum: yes
follow: true
loop: "{{ vars[item.name]['services'] | fileslist }}" loop: "{{ vars[item.name]['services'] | fileslist }}"
loop_control: loop_control:
loop_var: file loop_var: file
@ -29,7 +28,6 @@
path: "/var/lib/risotto/configurations/{{ item.name }}{{ file.name }}" path: "/var/lib/risotto/configurations/{{ item.name }}{{ file.name }}"
checksum: sha256 checksum: sha256
get_checksum: yes get_checksum: yes
follow: true
loop: "{{ vars[item.name]['services'] | fileslist }}" loop: "{{ vars[item.name]['services'] | fileslist }}"
loop_control: loop_control:
loop_var: file loop_var: file
@ -38,12 +36,12 @@
- name: "Configuration's file is up to date in {{ item.name }}" - name: "Configuration's file is up to date in {{ item.name }}"
debug: debug:
msg: "file is {{ 'out of date' if not file[1].stat.exists or (not 'checksum' in file[0].stat and 'checksum' in file[1].stat) or ('checksum' in file[0].stat and not 'checksum' in file[1].stat) or ('checksum' in file[0].stat and 'checksum' in file[1].stat and file[0].stat.checksum != file[1].stat.checksum) else 'up to date' }}" msg: "file is {{ 'out of date' if not file[1].stat.exists or file[0].stat.checksum != file[1].stat.checksum else 'up to date' }}"
changed_when: not file[1].stat.exists or (not 'checksum' in file[0].stat and 'checksum' in file[1].stat) or ('checksum' in file[0].stat and not 'checksum' in file[1].stat) or ('checksum' in file[0].stat and 'checksum' in file[1].stat and file[0].stat.checksum != file[1].stat.checksum) changed_when: not file[1].stat.exists or file[0].stat.checksum != file[1].stat.checksum
loop: "{{ local_configuration.results | zip(remote_configuration.results) | list }}" loop: "{{ local_configuration.results | zip(remote_configuration.results) | list }}"
loop_control: loop_control:
loop_var: file loop_var: file
label: "{{ file[0]['file']['name'] }}" label: "{{ file[0]['stat']['path'] }}"
ignore_errors: true ignore_errors: true
register: up_to_date_configuration register: up_to_date_configuration
@ -62,24 +60,6 @@
format: tar format: tar
when: up_to_date_configuration.changed when: up_to_date_configuration.changed
- name: "Remove old image {{ vars | modulename(item.name) }}"
file:
path: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}.tar"
state: absent
when: delete_old_image == true
- name: "Stop machine {{ item.name }}"
machinectl:
state: stopped
machines: "{{ item.name }}"
when: delete_old_image == true
- name: "Remove old machine {{ item.name }}"
file:
path: /var/lib/machines/{{ item.name }}
state: absent
when: delete_old_image == true
- name: "Create system directory for {{ item.name }}" - name: "Create system directory for {{ item.name }}"
file: file:
path: /var/lib/machines/{{ item.name }} path: /var/lib/machines/{{ item.name }}
@ -89,7 +69,6 @@
- name: "Check image for {{ item.name }}" - name: "Check image for {{ item.name }}"
stat: stat:
path: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}.tar" path: "/var/lib/risotto/images/{{ vars | modulename(item.name) }}.tar"
follow: true
register: register_name register: register_name
when: system_directory_created.changed when: system_directory_created.changed

View file

@ -21,11 +21,6 @@
dest: /var/lib/risotto/configurations/{{ item | basename }}/ dest: /var/lib/risotto/configurations/{{ item | basename }}/
loop: "{{ lookup('fileglob', '/tmp/new_configurations/*', wantlist=True) }}" loop: "{{ lookup('fileglob', '/tmp/new_configurations/*', wantlist=True) }}"
- name: "Enable machines"
machinectl:
state: enabled
machines: "{{ vars | machineslist(only_name=True) }}"
- name: "Start machines" - name: "Start machines"
machinectl: machinectl:
state: started state: started

View file

@ -131,7 +131,6 @@ fi
if [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs ] && [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs ]; then if [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs ] && [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs ]; then
echo " - différence(s) avec les paquets de base" echo " - différence(s) avec les paquets de base"
diff -u "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs "$BASE_PKGS_FILE" && INSTALL=false || INSTALL=true diff -u "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs "$BASE_PKGS_FILE" && INSTALL=false || INSTALL=true
[ ! -f "$IMAGE_NAME_RISOTTO_IMAGE_NAME" ] && INSTALL=true
else else
INSTALL=true INSTALL=true
fi fi

View file

@ -1,52 +0,0 @@
#!/bin/bash -e
MACHINES=""
for nspawn in $(ls /etc/systemd/nspawn/*.nspawn); do
nspawn_file=$(basename $nspawn)
machine=${nspawn_file%.*}
MACHINES="$MACHINES$machine "
done
STARTED=""
DEGRADED=""
found=true
idx=0
while [ $found = true ]; do
found=false
echo "tentative $idx"
for machine in $MACHINES; do
if ! echo $STARTED | grep -q " $machine "; then
status=$(machinectl -q shell $machine /usr/bin/systemctl is-system-running 2>/dev/null || echo "not started")
if echo "$status" | grep -q degraded; then
STARTED="$STARTED $machine "
DEGRADED="$DEGRADED $machine"
elif echo "$status" | grep -q running; then
STARTED="$STARTED $machine "
else
found=true
echo "status actuel de $machine : $status"
fi
fi
done
sleep 2
idx=$((idx+1))
if [ $idx = 60 ]; then
break
fi
done
retcode=0
for machine in $MACHINES; do
if ! echo "$STARTED" | grep -q " $machine "; then
echo
echo "========= $machine"
machinectl -q shell $machine /usr/bin/systemctl is-system-running 2>/dev/null || echo "not started"
fi
done
echo $DEGRADED
for machine in $DEGRADED; do
echo
echo "========= $machine"
machinectl -q shell $machine /usr/bin/systemctl --state=failed --no-legend --no-pager
retcode=1
done
exit $retcode

View file

@ -15,7 +15,7 @@ ls /var/lib/risotto/images_files/ | while read image; do
/usr/local/sbin/build_image "$image" /usr/local/sbin/build_image "$image"
fi fi
done done
#rm -f $IMAGE_BASE_RISOTTO_BASE_DIR*.build rm -f $IMAGE_BASE_RISOTTO_BASE_DIR*.build
MACHINES="" MACHINES=""
for nspawn in $(ls /etc/systemd/nspawn/*.nspawn); do for nspawn in $(ls /etc/systemd/nspawn/*.nspawn); do
@ -23,11 +23,11 @@ for nspawn in $(ls /etc/systemd/nspawn/*.nspawn); do
machine=${nspawn_file%.*} machine=${nspawn_file%.*}
MACHINES="$MACHINES$machine " MACHINES="$MACHINES$machine "
MACHINE_MACHINES_DIR="/var/lib/machines/$machine" MACHINE_MACHINES_DIR="/var/lib/machines/$machine"
echo "Install machine $machine"
SHA_MACHINE="$RISOTTO_DIR/configurations/sha/$machine".sha SHA_MACHINE="$RISOTTO_DIR/configurations/sha/$machine".sha
content=$(cat $SHA_MACHINE) content=$(cat $SHA_MACHINE)
IMAGE_NAME_RISOTTO_IMAGE_NAME=${content##* } IMAGE_NAME_RISOTTO_IMAGE_NAME=${content##* }
diff -q "$IMAGE_NAME_RISOTTO_IMAGE_NAME".sha "$SHA_MACHINE" > /dev/null || ( diff -q "$IMAGE_NAME_RISOTTO_IMAGE_NAME".sha "$SHA_MACHINE" || (
echo "Reinstall machine $machine"
machinectl stop $machine machinectl stop $machine
while true; do while true; do
machinectl status "$machine" > /dev/null 2>&1 || break machinectl status "$machine" > /dev/null 2>&1 || break
@ -41,4 +41,39 @@ for nspawn in $(ls /etc/systemd/nspawn/*.nspawn); do
) )
done done
machinectl start $MACHINES machinectl start $MACHINES
diagnose STARTED=""
DEGRADED=""
found=true
idx=0
while [ $found = true ]; do
found=false
echo "tentative $idx"
for machine in $MACHINES; do
if ! echo $STARTED | grep -q " $machine "; then
status=$(machinectl -q shell $machine /usr/bin/systemctl is-system-running || true)
if echo "$status" | grep -q degraded; then
STARTED="$STARTED $machine "
DEGRADED="$DEGRADED $machine"
elif echo "$status" | grep -q running; then
STARTED="$STARTED $machine "
else
found=true
echo "status actuel de $machine : $status"
fi
fi
done
sleep 2
idx=$((idx+1))
if [ $idx = 60 ]; then
break
fi
done
retcode=0
for machine in $DEGRADED; do
echo
echo "========= $machine"
machinectl -q shell $machine /usr/bin/systemctl --state=failed --no-legend --no-pager
retcode=1
done
exit $retcode

View file

@ -163,8 +163,8 @@ def load_applicationservice(appname: str,
suppliers.setdefault(supplier, []) suppliers.setdefault(supplier, [])
if appname not in suppliers[supplier]: if appname not in suppliers[supplier]:
suppliers[supplier].append(appname) suppliers[supplier].append(appname)
if 'distribution' in app and app['distribution']: if 'distribution' in app:
distribution = appname distribution = app['distribution']
else: else:
distribution = None distribution = None
for xml in app.get('depends', []): for xml in app.get('depends', []):
@ -181,7 +181,7 @@ def load_applicationservice(appname: str,
) )
if ret: if ret:
if distribution: if distribution:
raise Exception(f'duplicate distribution for {cfg.module_name}: {distribution} and {ret} (dependencies: {cfg.depends}) ') raise Exception(f'duplicate distribution for {cfg.module_name} ({distribution} and {ret})')
distribution = ret distribution = ret
return distribution return distribution
@ -209,7 +209,7 @@ def load_image_informations(module_name: str,
) )
if ret: if ret:
if distribution: if distribution:
raise Exception(f'duplicate distribution for {cfg.module_name}: {distribution} and {ret} (dependencies: {cfg.depends}) ') raise Exception(f'duplicate distribution for {cfg.module_name} ({distribution} and {ret})')
distribution = ret distribution = ret
if module_name != 'host' and not distribution: if module_name != 'host' and not distribution:
raise Exception(f'cannot found any linux distribution for {module_name}') raise Exception(f'cannot found any linux distribution for {module_name}')