<p>I found your post while fighting with ERROR: Cannot uninstall requests 2.25.1, RECORD file not found. Hint: The package was installed by rpm.  in Amazon Linux 2023 AMI 2023.0.20230517.1 x86_64 HVM kernel-6.1</p>
<p>You gave me an idea to try locally (ec2-user account, not root) and it seems that commenting out become: true line fixes the problem for me. But I'm using docker_container not docker compose.</p>

CC BY-SA 4.0
2023-06-05T22:07:46.153Z
2023-06-05T22:08:58.240Z
2023-06-05T22:08:58.240Z
Andrey K
<p>I have also got the same issue while practicing Ansible lab from &quot;Techworld with Nana&quot; boot camp, Below are steps that resolved my issue:</p>
<p>My machine Platform: Amazon Linux (Inferred)</p>
<p><strong>Did docker python module installation as ec2-user</strong>, instead of mixing it with other rpm installations as the root user</p>
<pre><code>- name: Install docker python module
  hosts: aws
  become: yes
  become_user: ec2-user
  tasks:
    - name: Install docker python module #This is dependency with ansible docker_image module
      pip:
        name: docker
</code></pre>
<p>Full Ansible playbook in case if you are interested</p>
<pre><code>---
- name: Install python3,docker and docker-compose
  hosts: aws
  become: yes
  tasks:
    - name: Make sure python3 and docker are installed
      vars: 
        ansible_python_interpreter: /usr/bin/python
      dnf:  #yum module as ofnow supports only python2 interpreter
        name: 
          - python3
          - docker
          - python3-pip
        update_cache: yes
        state: present
    - name: Install docker-compose
      get_url: 
        url: https://github.com/docker/compose/releases/download/1.27.4/docker-compose-Linux-{{lookup('pipe', 'uname -m')}} #using &quot;lookup&quot; from jinja template to interpret commands inside url
        dest: /usr/local/bin/docker-compose
        mode: +x
    - name: Ensure docker is running
      systemd:
        name: docker
        state: started


- name: Add user to docker group
  hosts: aws
  become: yes
  tasks:
    - name: Add ec2-user to docker group
      user:
        name: ec2-user
        groups: docker
        append: yes
    - name: Reconnect to server session
      meta: reset_connection  #To reset connection immediate after above task

- name: Install docker python module
  hosts: aws
  become: yes
  become_user: ec2-user
  tasks:
    - name: Install docker python module #This is dependency with ansible docker_image module
      pip:
        name: docker

- name: Test docker pull
  hosts: aws
  tasks:
    - name: pull redis
      # command: docker pull redis
      docker_image:
        name: redis
        source: pull
</code></pre>

CC BY-SA 4.0
2023-07-26T03:08:35.703Z
2023-07-26T03:08:35.703Z
Kishore Uppala
<p>I'm trying to run an ansible playbook that installs docker and docker-compose and runs a compose file on a ec2 t2.micro.</p>
<p>To use the docker modules in ansible, I need to have docker and docker-compose python modules installed in the ec2.</p>
<p>Here is my playbook:</p>
<pre><code>- name: Update yum repo, install docker, pip, docker-compose &amp; pip and python modules
  hosts: all
  become: true
  tasks:
    - name: update yum repo and cache
      yum: 
        name: '*'
        state: latest
        update_cache: true 
    - name: install docker and pip
      yum: 
        name:
          - docker
          - pip
    - name: download and install docker-compose 
      get_url:
        url: https://github.com/docker/compose/releases/latest/download/docker-compose-Linux-{{lookup('pipe','uname -m')}}
        dest: /usr/local/bin/docker-compose
        mode: +x
    - name: start docker daemon
      systemd:  
        name: docker
        state: started
  ########################################################### this is the trouble part      
    - name: Install docker and docker-compose python module
      pip:
        name: 
          - docker
          - docker-compose
  ############################################################  

</code></pre>
<p>the rest of the playbook adds ec2-user to the docker group, resets the ec2 connection, copies docker-compose file to the server and executes it, which all works perfectly fine.</p>
<p>Take a look if required</p>
<pre><code>#play2
- name: Reset connection 
  hosts: all
  become: true
  tasks:    
    - name:  add ec2-user to docker group
      user: 
        name: ec2-user
        groups: docker
        append: yes    
    - name: reconnect to server session
      meta: reset_connection  
#play3
- name: start docker containers
  hosts: all
  vars_files:
    - docker-vars.yml
  tasks:
    - name: copy docker-compose file
      copy: # copy files from controller to remote node
        src: /home/ansible-project/docker-compose.yaml
        dest: /home/ec2-user/docker-compose.yaml
    - name: login to docker private repo
      docker_login:
        registry_url: https://index.docker.io/v1
        username: &quot;{{user_name}}&quot; 
        password: &quot;{{docker_passwd}}&quot;  
    - name: execute docker-compose and start container
      docker_compose: 
        project_src: /home/ec2-user
        state: present # equivalent of docker-compose up 
</code></pre>
<p>My host file is simple with a single group and 1 server-ip configured with ansible_user and ssh private key for the login. The docker-vars.yaml has only my docker username and passwd.</p>
<p>I have tried to run the playbook by installing python3 specifically and select the &quot;interpreter_python= /usr/bin/python3&quot; in the ansible.cfg file and also using the default python installed i,e usr/bin/python3.9, but the playbook runs into an error saying:</p>
<blockquote>
<blockquote>
<blockquote>
<p>&quot;Found existing installation: requests 2.25.1\n\n:stderr:ERROR: Cannot uninstall requests 2.25.1 Hint: The package was installed by rpm.&quot;</p>
</blockquote>
</blockquote>
</blockquote>
<p>But if I manually log in to the ec2 and do</p>
<pre><code>$ pip install docker 
$ pip install docker-compose
</code></pre>
<p>the modules are successfully installed. And if I comment out the highlighted code and run the playbook it executes successfully.</p>
<p>I need to run this completely in single click, as I have to integrate it into the terraform file later, and I cannot perform that single step this manually.</p>

<docker><ansible><amazon-ec2><automation><configuration-management>
why does my Ansible playbook throw "Found existing installation: requests 2.25.1\n\n:stderr:ERROR: Cannot uninstall requests 2.25.1"?
Keshav Singh N
# why does my Ansible playbook throw "Found existing installation: requests 2.25.1\n\n:stderr:ERROR: Cannot uninstall requests 2.25.1"?

(Asked by: username_0 on 2023-06-02)

I'm trying to run an ansible playbook that installs docker and docker-compose and runs a compose file on a ec2 t2.micro.
To use the docker modules in ansible, I need to have docker and docker-compose python modules installed in the ec2.
Here is my playbook:
- name: Update yum repo, install docker, pip, docker-compose & pip and python modules
  hosts: all
  become: true
  tasks:
    - name: update yum repo and cache
      yum: 
        name: '*'
        state: latest
        update_cache: true 
    - name: install docker and pip
      yum: 
        name:
          - docker
          - pip
    - name: download and install docker-compose 
      get_url:
        url: https://github.com/docker/compose/releases/latest/download/docker-compose-Linux-{{lookup('pipe','uname -m')}}
        dest: /usr/local/bin/docker-compose
        mode: +x
    - name: start docker daemon
      systemd:  
        name: docker
        state: started
  ########################################################### this is the trouble part      
    - name: Install docker and docker-compose python module
      pip:
        name: 
          - docker
          - docker-compose
  ############################################################  


the rest of the playbook adds ec2-user to the docker group, resets the ec2 connection, copies docker-compose file to the server and executes it, which all works perfectly fine.
Take a look if required
#play2
- name: Reset connection 
  hosts: all
  become: true
  tasks:    
    - name:  add ec2-user to docker group
      user: 
        name: ec2-user
        groups: docker
        append: yes    
    - name: reconnect to server session
      meta: reset_connection  
#play3
- name: start docker containers
  hosts: all
  vars_files:
    - docker-vars.yml
  tasks:
    - name: copy docker-compose file
      copy: # copy files from controller to remote node
        src: /home/ansible-project/docker-compose.yaml
        dest: /home/ec2-user/docker-compose.yaml
    - name: login to docker private repo
      docker_login:
        registry_url: https://index.docker.io/v1
        username: "{{user_name}}" 
        password: "{{docker_passwd}}"  
    - name: execute docker-compose and start container
      docker_compose: 
        project_src: /home/ec2-user
        state: present # equivalent of docker-compose up 

My host file is simple with a single group and 1 server-ip configured with ansible_user and ssh private key for the login. The docker-vars.yaml has only my docker username and passwd.
I have tried to run the playbook by installing python3 specifically and select the "interpreter_python= /usr/bin/python3" in the ansible.cfg file and also using the default python installed i,e usr/bin/python3.9, but the playbook runs into an error saying:



"Found existing installation: requests 2.25.1\n\n:stderr:ERROR: Cannot uninstall requests 2.25.1 Hint: The package was installed by rpm."



But if I manually log in to the ec2 and do
$ pip install docker 
$ pip install docker-compose

the modules are successfully installed. And if I comment out the highlighted code and run the playbook it executes successfully.
I need to run this completely in single click, as I have to integrate it into the terraform file later, and I cannot perform that single step this manually.

**Tags:** docker, ansible, amazon-ec2, automation, configuration-management


---

## 2 answers

### Answer by username_1 on 2023-06-05. Score: 0

I found your post while fighting with ERROR: Cannot uninstall requests 2.25.1, RECORD file not found. Hint: The package was installed by rpm. in Amazon Linux 2023 AMI 2023.0.20230517.1 x86\_64 HVM kernel-6.1

You gave me an idea to try locally (ec2-user account, not root) and it seems that commenting out become: true line fixes the problem for me. But I'm using docker\_container not docker compose.


---

### Answer by username_2 on 2023-07-26. Score: 0

I have also got the same issue while practicing Ansible lab from "Techworld with Nana" boot camp, Below are steps that resolved my issue:
My machine Platform: Amazon Linux (Inferred)
Did docker python module installation as ec2-user, instead of mixing it with other rpm installations as the root user
- name: Install docker python module
  hosts: aws
  become: yes
  become_user: ec2-user
  tasks:
    - name: Install docker python module #This is dependency with ansible docker_image module
      pip:
        name: docker

Full Ansible playbook in case if you are interested
---
- name: Install python3,docker and docker-compose
  hosts: aws
  become: yes
  tasks:
    - name: Make sure python3 and docker are installed
      vars: 
        ansible_python_interpreter: /usr/bin/python
      dnf:  #yum module as ofnow supports only python2 interpreter
        name: 
          - python3
          - docker
          - python3-pip
        update_cache: yes
        state: present
    - name: Install docker-compose
      get_url: 
        url: https://github.com/docker/compose/releases/download/1.27.4/docker-compose-Linux-{{lookup('pipe', 'uname -m')}} #using "lookup" from jinja template to interpret commands inside url
        dest: /usr/local/bin/docker-compose
        mode: +x
    - name: Ensure docker is running
      systemd:
        name: docker
        state: started


- name: Add user to docker group
  hosts: aws
  become: yes
  tasks:
    - name: Add ec2-user to docker group
      user:
        name: ec2-user
        groups: docker
        append: yes
    - name: Reconnect to server session
      meta: reset_connection  #To reset connection immediate after above task

- name: Install docker python module
  hosts: aws
  become: yes
  become_user: ec2-user
  tasks:
    - name: Install docker python module #This is dependency with ansible docker_image module
      pip:
        name: docker

- name: Test docker pull
  hosts: aws
  tasks:
    - name: pull redis
      # command: docker pull redis
      docker_image:
        name: redis
        source: pull


---

