From 08c26311b2079cb3e8f17699a578c6b6c8376039 Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Mon, 22 Feb 2021 09:50:04 +0000 Subject: [PATCH] Install into /opt/ansible when running as root --- ansible-setup.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ansible-setup.sh b/ansible-setup.sh index 2c231df..3bca3dd 100755 --- a/ansible-setup.sh +++ b/ansible-setup.sh @@ -14,12 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +if [ $(id -u) -eq 0 ]; then + install_path=/opt/ansible + bin_path=/usr/local/bin +else + install_path="$HOME/opt/ansible" + bin_path="$HOME/bin" +fi + pipinstall () { ./bin/pip install --upgrade $1 } create_link () { - ln -sf "../opt/ansible/bin/$1" "$HOME/bin/$1" + ln -sf "$install_path/bin/$1" "$bin_path/$1" } py3cmd="$(command -v python3)" @@ -31,17 +39,17 @@ else fi if [ ! -x "$HOME/opt/ansible/bin/ansible-playbook" ]; then - python3 -m venv "$HOME/opt/ansible" || exit 1 + python3 -m venv "$install_path" || exit 1 fi -pushd "$HOME/opt/ansible" +pushd "$install_path" pipinstall pip pipinstall wheel pipinstall ansible popd -if [ ! -d "$HOME/bin" ]; then - mkdir "$HOME/bin" +if [ ! -d "$bin_path" ]; then + mkdir "$bin_path" fi for command in \