Add a base role
Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
This commit is contained in:
parent
d42105badb
commit
a7fb205256
3 changed files with 53 additions and 0 deletions
26
ansible/roles/base/files/conditional-reload.sh
Normal file
26
ansible/roles/base/files/conditional-reload.sh
Normal 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
|
10
ansible/roles/base/files/conditional-restart.sh
Normal file
10
ansible/roles/base/files/conditional-restart.sh
Normal 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
|
17
ansible/roles/base/tasks/main.yml
Normal file
17
ansible/roles/base/tasks/main.yml
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue