Skip to content

Instantly share code, notes, and snippets.

@MiLk
Last active August 29, 2015 14:10
Show Gist options
  • Save MiLk/a822335becb47b953d62 to your computer and use it in GitHub Desktop.
Save MiLk/a822335becb47b953d62 to your computer and use it in GitHub Desktop.
#!/bin/bash
conf_file=
disable_gpg_check=
disablerepo=
enablerepo=
name=
state="present"
changed=0
for option in $(cat $1); do
IFS='='
arr=(${option})
case "${arr[0]}" in
"conf_file")
conf_file="--config=${arr[1]}"
;;
"disable_gpg_check")
if [ "${arr[1]}" = "yes" ]; then
disable_gpg_check="--nogpgcheck"
fi
;;
"disablerepo")
disablerepo="--disablerepo=${arr[1]}"
;;
"enablerepo")
enablerepo="--enablerepo=${arr[1]}"
;;
"name")
name=${arr[1]}
;;
"state")
state=${arr[1]}
;;
esac
done
if [ -z ${name} ]; then
echo 'failed=True msg="Module needs name argument."'
exit 0
fi
if [ "${state}" = "latest" ]; then
IFS=','
for i in ${name}; do
if [ -z "$(sudo rpm -qa ${i})" ]; then
sudo yum -y install ${i} ${conf_file} ${disable_gpg_check} ${disablerepo} ${enablerepo} >/dev/null
changed=1
else
sudo yum -y update ${i} ${conf_file} ${disable_gpg_check} ${disablerepo} ${enablerepo} >/dev/null
changed=1
fi
done
elif [ "${state}" = "install" ]; then
IFS=','
for i in ${name}; do
if [ -z "$(sudo rpm -qa ${i})" ]; then
sudo yum -y install ${i} ${conf_file} ${disable_gpg_check} ${disablerepo} ${enablerepo} >/dev/null
changed=1
fi
done
elif [ "${state}" = "absent" ]; then
IFS=','
for i in ${name}; do
if [ ! -z "$(sudo rpm -qa ${i})" ]; then
sudo yum -y remove ${i} ${conf_file} ${disable_gpg_check} ${disablerepo} ${enablerepo} >/dev/null
changed=1
fi
done
else
echo 'failed=True msg="The state argument is invalid."'
fi
if [ ${changed} -eq 1 ]; then
echo "changed=True msg=ok"
else
echo "changed=False msg=ok"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment