Skip to content

Instantly share code, notes, and snippets.

@nweddle
Created February 25, 2020 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nweddle/d1d012ac30e45926aa4f1bea81f27f7c to your computer and use it in GitHub Desktop.
Save nweddle/d1d012ac30e45926aa4f1bea81f27f7c to your computer and use it in GitHub Desktop.
Ubuntu Idempotent Ansible Install Check
#!/usr/bin/env bash
set -euo pipefail
output="$(apt-cache policy ansible)"
installed="$(echo "$output" | sed -n -r 's/^(.*)(Installed: )(.*)$/\3/p')"
candidate="$(echo "$output" | sed -n -r 's/^(.*)(Candidate: )(.*)$/\3/p')"
if [[ $installed != "$candidate" ]]; then
echo Install Ansible
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo apt update
sudo apt install --yes software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install --yes ansible
else
echo Ansible up to date
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment