Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

installation - 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,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...