Ansible
Install
Virtualenv (python)
Python virtual environment is highly recommended to isolate the python packages in shared systems and avoid broken dependencies when projects needs specific packages/versions.
To use python virtual environment (recommended when using many ansible projects) you need to install the base python package on your system (need elevated permissions - sudo
):
-
Install using the System's package manager:
-
Install using python3 package management (pip3):
- Create the virtuale environment
in general
.venv
is the default virtualenvironemnt that resides in the same directory of the project that the virtualenv will be used (ex. dirmy-project
)
- Enter in the project's directory and enable the virtual environment
NOTE1: the terminal should have a prefix (
(.venv)
) indicating that the venv is enabled, like that:
NOTE2: all the python environment should be behind the path
.venv
, you can see the new path of pip:
-
Install the Ansible OR use requirements.txt file to persiste packages w/ versions
-
ad-hoc install
-
requirements.txt
file
requirements.txt content:
install
Container
To use ansible in a container, just use the same strategy of python virtual environment isolated.
There is two ways:
- install dependencies directly on Dockerfile
, OR
- create a requirements.txt
file with it's dependencies (highly recommended)
- Create
Dockerfile
a) Create Dockerfile
with requirements.txt
file:
FROM centos:latest
WORKDIR /ansible
COPY requirements.txt .
RUN yum -y install python3-pip && \
pip3 install -r requirements.txt
b) OR, leave all dependences inside Dockerfile
:
FROM centos:latest
WORKDIR /ansible
COPY requirements.txt .
RUN yum -y install python3-pip && \
pip3 install ansible
- Build the image
- Run the container w/ ad-hoc command
ping