简体   繁体   中英

Is this the correct way of distributing Ansible on Ubuntu 20.04?

I am building an Ansible server using Ubuntu Server 20.04 64bit and Ansible 2.8.13. Among other things ansible will manage some mysql and postgres servers among other things. In the near future there might be a version upgrade of ansible as well. So based on my limited knowledge this is what I have so far

# Install
sudo apt-get -yqq install python3-pip python3-venv mysql-client postgresql-client libpq-dev

sudo python3 -m venv --clear /opt/ansible

. /opt/ansible/bin/activate
pip3 install wheel setuptools
pip3 install PyMySQL psycopg2 ansible==2.8.13
deactivate

Given that in order to run those executable one has to write wrapper scripts for each ansible executable to pass over into main session.

/usr/local/bin/ansible-playbook.2.8.sh

#!/usr/bin/env sh

. /opt/ansible/bin/activate
/opt/ansible/bin/ansible-playbook "$@"
result=$?
deactivate
exit "${result}"

And finally map the main executable with update-alternatives

update-alternatives --install /usr/local/bin/ansible-playbook ansible-playbook \
  "/usr/local/bin/ansible-playbook-2.8.sh" 1

Is this considered decent approach in 2021 or is there something better?

Thanks,

Actually after some more testing and reading this is what I came up with:

# Install
sudo apt-get -yqq install python3-pip python3-venv

sudo python3 -m venv --clear /opt/ansible

. /opt/ansible/bin/activate
pip3 install wheel
pip3 install ansible==2.8.13
deactivate

update-alternatives --install \
  /usr/local/bin/ansible-playbook ansible-playbook \
  /opt/ansible/bin/ansible-playbook 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM