Add a base role

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
This commit is contained in:
Pierre-Yves Chibon 2021-01-20 11:38:46 +01:00
parent d42105badb
commit a7fb205256
3 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,26 @@
#!/bin/bash
# reload SERVICE only if PACKAGE is installed.
# We use this throughout handlers/restart_services.yml
SERVICE=$1
PACKAGE=$2
rpm -q $PACKAGE
INSTALLED=$?
if [ $INSTALLED -eq 0 ]; then
echo "Checking if $SERVICE is running"
/sbin/service $SERVICE status >& /dev/null
if [ $? == 0 ]; then
echo "Package $PACKAGE installed and running. Attempting reload of $SERVICE."
/sbin/service $SERVICE reload
exit $? # Exit with the /sbin/service status code
fi
echo "Package $PACKAGE is install, but $SERVICE is not running, skipping..."
exit 0
fi
# If the package wasn't installed, then pretend everything is fine.
echo "Package $PACKAGE not installed. Skipping reload of $SERVICE."
exit 0

View file

@ -0,0 +1,10 @@
#!/bin/bash
#
# We use this to try and restart a service.
# If it's not running, do nothing.
# If it is running, restart it.
#
SERVICE=$1
# Check if service unit is present before trying to restart it
/usr/bin/systemctl cat $1.service &>/dev/null && /usr/bin/systemctl try-restart $1 || true

View file

@ -0,0 +1,17 @@
- name: Install packages that are useful in general
package: name={{ item }} state=present
with_items:
- vim
- tmux
tags:
- base
- package
- name: Install the conditional-restart/reload scripts
copy: src={{ item }} dest=/usr/local/bin
owner=root group=root mode=0755
with_fileglob:
- conditional*
tags:
- config
- base