Hi All,
I’m managing a set of about 60 Debian computers with a deployment script.
Purpose is to copy some system files to configure the system (login manager, …) and have a default /home/user directory (bookmarks, pinneds apps, …).
I’d like to switch to Ansible to avoid having to run the script manually or each system, and to benefit from “idempotence” (I love the word
).
I’m not asking to do the job on my behalf, just would like to confirm that my script building blocks properly translate into playbook entries.
Software updates
Script
apt update
apt upgrade -y
apt install -y rsync openssh-client openssh-server net-tools
apt purge -y --autoremove gnome-games
Ansible
tasks:
- name: updates
block:
- name: update
apt:
update_cache: yes
- name: upgrade
apt:
upgrade: dist
- name: install
apt:
name:
- rsync
- openssh-client
- openssh-server
- net-tools
state: present
- name: remove
apt:
name: gnome-games
state: absent
autoremove: yes
Disabling passwords
Script
passwd -d guest
Ansible
- name: Désactivation du mot de passe pour l'utilisateur guest
user:
name: guest
password: "" # Mot de passe vide
Remove some files and copy some others
Script
rm -Rf /usr/share/wayland-sessions/*
rm -Rf /usr/share/xsessions/*
rm -Rf /etc/skel/*
rm -Rf /home/guest/*
rm -Rf /home/guest/.*
rsync -az --progress --ignore-times root@$SKELETON_SERVER:$SKELETON_PATH/ /etc/skel/
rsync -az --progress --ignore-times /etc/skel/ /
Ansible
- name: Copie du skeleton depuis le serveur
block:
- name: Suppression des sessions Wayland et X existantes
file:
path: "{{ item }}"
state: absent
loop:
- /usr/share/wayland-sessions/
- /usr/share/xsessions/
- name: Copie du skeleton depuis le serveur distant
synchronize:
src: "root@{{ skeleton_server }}:{{ skeleton_path }}/"
dest: "{{ local_dest }}etc/skel/"
mode: push
archive: yes
compress: yes
- name: Application du skeleton à la racine
synchronize:
src: "{{ local_dest }}etc/skel/"
dest: "{{ local_dest }}/"
mode: pull
archive: yes
compress: yes
Ownership and permission changes
Script
chown -R guest:guest /home/guest
chmod +x /usr/share/sddm/scripts/Xstop
Ansible
- name: Changement de propriétaire pour /home/guest
file:
path: /home/guest
owner: guest
group: guest
recurse: yes
Other actions required
- I don’t know how to change permissions on folders
- I don’t know how to invoke extra specific cxommands such as
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
sudo dconf update #pour couvrir la partie Cinnamon
sudo update-grub
systemctl restart ssh
Can you please help me confirm that my building blocks look OK?
Are there ways to run commands such as the ones at the bottom of my list?
Ultimately, if I have a working script, should I consider copying the script and simply running it on my clients via Ansible, and avoid converting the whole script into a playbook?
Thanks a lot!