Ansible : Fix Package Dependency Error
1 min readApr 10, 2022
Sometime when you work on ansible playbook and use module, the module may not work correctly as some library dependency may be missing. One example is when trying to use docker_image module to pull an image.
YAML FILE SNIPPET:
- hosts: awsnode
tasks:
- name: Download the docker repo.
get_url:
url: "https://download.docker.com/linux/rhel/docker-ce.repo"
dest: "/etc/yum.repos.d"
# There is issue on above docker-ce.repo URLS, the packages not avaialble under rhel, it's available under centos.
# Below steps will first replace the existing repo file's rhel string with centos.- name: Replace the rhel keyword in repo file with centos.
replace:
path: "/etc/yum.repos.d/docker-ce.repo"
regexp: 'rhel'
replace: 'centos'
- name: Install Docker Software
package:
name: "docker-ce"
state: present
- name: Start docker service
service:
name: "docker"
state: "started"
- name: Pull docker Image name ubuntu
docker_image:
name: ubuntu
tag: 14.04
Solution is to install the specific python library.
- name: Install pip command to install python library.
package:
name: "python38-pip"
state: present
- name: Install docker-py python Library.
pip:
name: "docker-py"