1

I'm trying to install Ansible using sudo apt-get install ansible, but I'm getting the following output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies: ansible-core : Depends: python3-jinja2 but it is not installable Depends: python3-packaging but it is not installable Depends: python3-resolvelib but it is not installable Recommends: sshpass but it is not installable E: Unable to correct problems, you have held broken packages.

How can I install Ansible?

1 Answers1

1

Ansible has an installation guide ready which will guide you through any missing dependencies as well: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html

There is also the development version on GitHub: https://github.com/ansible/ansible

Here are the basic guidelines, taken from the guide above:

  1. Locate where Python is installed using the following command:

    which python3
    
  2. Ensure that pip (part of Python) is installed by running this command:

    python3 -m pip -V
    

    If all is well, you should see something like the following:

    pip 21.0.1 from /usr/lib/python3.9/site-packages/pip (python 3.9)
    

    If so, pip is available, and you can move on to the next step.

    If you see an error like No module named pip, you’ll need to install pip under your chosen Python interpreter before proceeding. This may mean installing an additional OS package (for example, python3-pip), or installing the latest pip directly from the Python Packaging Authority by running the following:

    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
    python3 get-pip.py --user
    
  3. Install Ansible for the current user using pip in your selected Python environment:

    python3 -m pip install --user ansible
    

You haven't mentioned your Ubuntu release installation, so I assume you can have something above 18.04, for which the above should work out fine.

For anything extra, refer to the guide and Ansible's official website, mentioned in the start of this answer.

Good luck.