0

I am trying to build an image using a dockerfile that has ansible installed. However when I start the container and try to get Ansible verion I get bash: ansible: command not found.

This is my dockerfile


FROM centos:centos7.7.1908

RUN  yum check-update; \
   yum install -y gcc libffi-devel python3 epel-release; \
   yum install -y openssh-clients; \
   yum install -y sshpass; \
   yum clean all; \
   pip3 install --upgrade pip

RUN pip3 install "ansible==2.9.12"; \
   pip3 install boto; \
   pip3 install boto3; \
   pip3 install "pywinrm>=0.3.0"


I used docker build -t ansible:latest . It does have pywinrm, boto and boto3

[root@7dbc2587a975 /]# pip3 list
Package            Version
------------------ ---------
boto               2.49.0
boto3              1.23.10
botocore           1.26.10
certifi            2022.9.24
cffi               1.15.1
charset-normalizer 2.0.12
cryptography       38.0.4
idna               3.4
jmespath           0.10.0
ntlm-auth          1.5.0
pip                21.3.1
pycparser          2.21
python-dateutil    2.8.2
pywinrm            0.4.3
requests           2.27.1
requests-ntlm      1.1.0
s3transfer         0.5.2
setuptools         39.2.0
six                1.16.0
urllib3            1.26.13
xmltodict          0.13.0

I tried to remove all images docker rmi ansible

Edit: final docker file which seems to work:

FROM centos:centos7.7.1908

ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8

RUN  yum check-update; \
   yum install -y gcc libffi-devel python3 epel-release; \
   yum install -y openssh-clients; \
   yum install -y sshpass; \
   yum clean all; \
   pip3 install --upgrade pip
   
RUN pip3 install "ansible==2.9.12" && \ 
   pip3 install boto && pip3 install boto3 && pip3 install "pywinrm>=0.3.0"
Adrimus
  • 13
  • 5
  • 1
    Try `&&` instead of `;` as commands separator, so that your build fails when any command part fails. Now it's almost clear that `pip install ansible` failed and did not cause the whole build to fail. – STerliakov Dec 10 '22 at 20:28
  • 1
    in addition to @SUTerliakov 's comment. You can give pipe install a list of things to install. So you probably want to do `pip3 install ansible=2.9.12 boto ...` – The Fool Dec 10 '22 at 21:16
  • Thanks that was helpful, I got an error while installing and after searching I found this: ansible is only supported running under a utf-8 locale. https://github.com/ansible/ansible/issues/76213 – Adrimus Dec 11 '22 at 14:06
  • @TheFool Not sure what you meant by give pip install a list, I tried pip3 install "ansible==2.9.12" boto boto3 "pywinrm>=0.3.0", but that gave me error – Adrimus Dec 11 '22 at 14:13
  • 1
    without seeing the error, I cant tell you want went wrong. But pip understands multiple arguments. https://stackoverflow.com/a/9956813/9208887 – The Fool Dec 11 '22 at 15:33

0 Answers0