13

I have uninstall ansible 1.9.4 and install with sudo apt-get install ansible, the version 2.0.2. But when I execute:

ikerlan$ ansible --version
ansible 1.9.4

I have uninstall and reinstall using ansible ppa, when I install I can see this:

Preparing to unpack .../ansible_2.0.0.2-1ppa~trusty_all.deb ...
Unpacking ansible (2.0.0.2-1ppa~trusty) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Configurando ansible (2.0.0.2-1ppa~trusty) ...
Processing triggers for python-support (1.0.15) ...

But if I check ansible version:

ikerlan@ikerlan-docker:~$ ansible --version
    ansible 1.9.4
      configured module search path = None

If I run the next:

ikerlan@ikerlan-docker:~$ sudo dpkg -l | grep ansible
ii  ansible                                               2.0.0.2-1ppa~trusty                                 all          A radically simple IT automation platform

Any help? Thanks

Asier Gomez
  • 6,034
  • 18
  • 52
  • 105
  • Run `print -rl -- ${(ko)commands} | grep ansible` - do you get more than 1 result? Source - http://unix.stackexchange.com/a/120818/28596 – Ashley Jan 20 '16 at 14:51
  • If I run the next command: 'print -rl -- ${(ko)commands} | grep ansible', I can see the next: bash: ${(ko)commands}: wrong replacement @Ash – Asier Gomez Jan 20 '16 at 15:19
  • My mistake, that command is for `zsh`. For `bash` try `compgen -c | grep ansible`. – Ashley Jan 20 '16 at 15:21
  • Okey Thanks, I can see 12 results: 1.ansible | 2.ansible-galaxy | 3. ansible-pull | 4. ansible-doc | 5.ansible-playbook | 6.ansible-vault | 7.ansible | 8.ansible-galaxy | 9.ansible-pull | 10.ansible-doc | 11 ansible-playbook | 12. ansible-vault | I can see duplicated 'ansible' two times, is it normal? @Ash – Asier Gomez Jan 20 '16 at 15:23
  • Right so we have `ansible` twice. That to me indicates that they are not in order you expect so the wrong version is being used when you attempt to execute. Run - which `compgen -c` | grep ansible - which will give you the full path to - ansible - Feel free to edit your answer with this information as it will be easier than formatting in a comment. – Ashley Jan 20 '16 at 15:34
  • If I run: ikerlan@ikerlanKVM:~$ which compgen -c | grep ansible -which The result is: 0 (There appears a zero). Am I putting ok? Thanks – Asier Gomez Jan 20 '16 at 15:44
  • Stackoverflow isn't formatting the command correctly it's http://pastebin.com/RnkTnrNi – Ashley Jan 20 '16 at 15:45
  • I can see both ansible in the same path, both are /usr/local/bin/ansible. when I acces to /usr/local/bin only appears one ansible. @Ash – Asier Gomez Jan 20 '16 at 16:08
  • Looks like your `1.9.4` was installed by hand, not via a package, so installing a newer package left its files in place. – Charles Duffy Jan 20 '16 at 16:55
  • I have installed ansible 1.9.4 using the next command: *Ubuntu$ sudo apt-get install software-properties-common *Ubuntu$ sudo apt-add-repository ppa:ansible/ansible *Ubuntu$ sudo apt-get update *Ubuntu$ sudo apt-get install ansible @CharlesDuffy – Asier Gomez Jan 20 '16 at 17:05
  • If that's the case, dpkg should be able to tell you the name of the packages owning the old files so you can uninstall them (those packages, that is).. – Charles Duffy Jan 20 '16 at 17:17
  • What version of Linux are you using? – Ashley Jan 20 '16 at 17:18
  • I am using ubuntu 14.04 @Ash – Asier Gomez Jan 21 '16 at 13:18
  • @CharlesDuffy but what can I do with dpkg? and how can I do that? Thanks – Asier Gomez Jan 21 '16 at 13:21
  • @Asier, `dpkg-query -S /path/to/file` tells you which package owns a file. If running that on the ansible binary returned by `type ansible` tells you that it's a 1.9.x package, then you have your answer. The trickier case is if you have a newer ansible binary using an *older* library (which is presumably earlier in the Python search path); in that case, you'll want to ask the Python interpreter where it's getting that library from, and *then* use `dpkg-query` to find out which package (if any) owns it. – Charles Duffy Jan 21 '16 at 16:43
  • @Asier, ...in general, finding out where on disk a Python library is coming from (so you can then ask `dpkg-query` which package owns it) looks something like `python -c 'import ansible; print ansible.__file__'`. – Charles Duffy Jan 21 '16 at 16:45
  • @CharlesDuffy If I execute 'dpkg-query -S /path/to/file' It appears a lot of python files. example: ansible: /usr/share/pyshared/ansible/playbook/handler.py ansible: /usr/share/pyshared/ansible/modules/core/network/basics/uri.py – Asier Gomez Jan 22 '16 at 13:26
  • There's your answer -- those files are provided by the `ansible` package. – Charles Duffy Jan 22 '16 at 15:47
  • Thanks very much @CharlesDuffy finally I removed all the files of ansible and I reinstall ansible, and its works perfectly – Asier Gomez Jan 22 '16 at 15:51

4 Answers4

21

Here is the right way to upgrade it. Even after installing ansible correctly does not change the version. The solution i found here works nicely. https://groups.google.com/forum/#!topic/ansible-project/eCtBp2aDtCQ

sudo -H pip install --upgrade ansible

Just running this command upgrades and fixes the version too which we check using ansible --version

It will upgrade to latest like now its 2.1

Deepali Mittal
  • 996
  • 13
  • 20
20

There is no guarantee you get the latest version just because you uninstalled and reinstalled. As of now Ansible 2.0 is available only through PPA.

Ansible 2.0 Install

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible
helloV
  • 50,176
  • 7
  • 137
  • 145
  • I have tryed this solution but I see ansible 1.9.4, I uninstall ansible and I install using the commands you send me, but ansible version don't change. You can see in the description what I do. @helloV – Asier Gomez Jan 20 '16 at 16:51
  • What is the output of `sudo dpkg -l | grep ansible`? – helloV Jan 20 '16 at 18:03
  • I have put the output in the description, it says: ansible 2.0.0.2-1ppa~trusty – Asier Gomez Jan 21 '16 at 13:08
8

Most like you have actually at some point installed ansible twice - once via PIP and once via apt-get

if you sudo apt-get remove ansible and sudo pip uninstall ansible

then run

compgen -c | grep ansible

You should not have any results.

And then install from the PPA to get version 2

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

run e.g.

ansible-playbook --version

and you should now see

ansible-playbook 2.0.2.0

Jeremy Daalder
  • 201
  • 2
  • 4
  • Worked like a charm. THANK YOU! – Nicholas K Sep 04 '18 at 08:52
  • what if I still have a list of results after 'compgen...' even if the two first commands return 'ansible not installed'? – andymel May 10 '20 at 16:31
  • I guess it depends what those results are...but it sounds like you uninstalling failed for some reason. Or perhaps there's some 3rd way of installing ansible you've done in the past that needs yet another uninstall method? Not sure on that, sorry! – Jeremy Daalder May 10 '20 at 23:47
2

you can upgrade a single package using

sudo apt-get install --only-upgrade ansible

or purge the previous packages and config file using

sudo apt-get remove --purge ansible
sudo apt-get autoremove

then install from ppa

sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
captainchhala
  • 831
  • 1
  • 7
  • 14