Setup Ansible Control Node in Offline Environment - CloudCommandos/JohnChan GitHub Wiki
Assumptions
- You will be running Ansible in an Ubuntu Focal VM.
- You have private apt repositories
Prepare Packages
Start with an online VM that matches the specs of your target VM.
Configure apt uplink servers to your private apt repositories
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
sudo nano /etc/apt/sources.list
# This is just an example
deb http://private_apt_domain.com:8081/repository/apt-proxy-ubuntu/ focal main restricted universe multiverse
deb http://private_apt_domain.com:8081/repository/apt-proxy-ubuntu/ focal-updates main restricted universe multiverse
deb http://private_apt_domain.com:8081/repository/apt-proxy-ubuntu/ focal-security main restricted universe multiverse
deb http://private_apt_domain.com:8081/repository/apt-proxy-ubuntu/ focal-backports main restricted universe multiverse
deb http://private_apt_domain.com:8081/repository/apt-hosted-ubuntu-focal/ focal main
Install python3-pip and sshpass
sudo apt update
sudo apt install python3-pip
sudo apt install sshpass
Install ansible via pip3
pip3 install ansible
(Situational) Install other packages that your ansible playbooks may need
pip3 install pyopenssl
pip3 install pyvmomi
pip3 install pywinrm
pip3 install jmespath
Install pipdeptree via pip3 (we will use this tool to get pip package dependency tree)
pip3 install pipdeptree
Generate the requirements.txt file
pipdeptree -fl --warn silence | grep -P '^[\w0-9\-=.]+' > requirements.txt
Download packages specified in requirements.txt and store in pip3_packages folder
pip3 download -r requirements.txt -d ./pip3_packages
Setup Offline VM
(Situational) You may need to add into ~/.ssh/config support for legacy algorithms for SSH
nano ~/.ssh/config
Host x.x.x.x
KexAlgorithms +diffie-hellman-group1-sha1
Configure apt uplink servers to your private apt repositories (Same step in the online VM section).
Install python3-pip and sshpass
sudo apt update
sudo apt install python3-pip
sudo apt install sshpass
Transfer over all contents of pip3_packages folder and requirments.txt. Then install packages specified in requirements.txt offline using the packages in pip3_packages folder
sudo pip3 install -r requirements.txt --no-index --find-links ./pip3_packages