modules apt: only_upgrade fail

323 views
Skip to first unread message

richar...@gmail.com

unread,
Jul 21, 2016, 9:07:20 AM7/21/16
to Ansible Project
Hello,

Having either apt: only_upgrade=docker-engine in my playbook or running it on the command line as ansible all --sudo -m apt -a 'only_upgrade=docker-engine' fails with

```
xx.xxx.xx.xxx | FAILED! => {
    "changed": false, 
    "failed": true, 
    "msg": "Boolean docker-engine not in either boolean list"
}
```

In the document

only_upgrade(added in 2.1)
Only install/upgrade a package if it is already installed.

my local ansible version is
```
ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible']
```

my host docker version is 1.11.0,I just want to only upgrade this package docker-engine to 1.11.2

my playbook is here

```
---
- hosts: xxxx
  sudo: yes
  vars: 
     apt_packages: 
      - apt-transport-https
      - ca-certificates


  tasks:
   - name: add CA certificates are installed.
     apt: 
         name: "{{ item }}"
         update_cache: yes
     with_items: apt_packages
 
   - name: add apt-key of dockers  
     apt_key:
         keyserver: p80.pool.sks-keyservers.net
         id: 58118E89F3A912897C070ADBF76221572C52609D

   - name: modify /etc/apt/sources.list.d/docker.list 
     replace:     
         dest: /etc/apt/sources.list.d/docker.list
         regexp: '^deb http'
         replace: "deb https"

   - name: upgrade docker-engine
     apt:
         only_upgrade: docker-engine

``` 

Thanks!

Kai Stian Olstad

unread,
Jul 21, 2016, 10:44:46 AM7/21/16
to ansible...@googlegroups.com
On 21. juli 2016 03:44, richar...@gmail.com wrote:
> xx.xxx.xx.xxx | FAILED! => {
> "changed": false,
> "failed": true,
> "msg": "Boolean docker-engine not in either boolean list"
> }
> ```
>
> In the document
>
> only_upgrade(added in 2.1)
> Only install/upgrade a package if it is already installed.

The documentation also say the default value is false, so this option
can only be true or false.


> - name: upgrade docker-engine
> apt:
> only_upgrade: docker-engine

This should be
- name: upgrade docker-engine
apt:
name: docker-engine
only_upgrade: true

I also think you need to add state: latest to have it upgrade the package.

--
Kai Stian Olstad

richar...@gmail.com

unread,
Jul 28, 2016, 1:29:17 AM7/28/16
to Ansible Project, ansible-pr...@olstad.com
I just think this way is reinstall docker-engie to latest when you ues name and state=lastest 

it's different to upgrade this procedure


在 2016年7月21日星期四 UTC+8下午10:44:46,Kai Stian Olstad写道:

richar...@gmail.com

unread,
Jul 28, 2016, 1:54:03 AM7/28/16
to Ansible Project, ansible-pr...@olstad.com
Thanks for you suggestion but I just get this when use you way

```
   - name: upgrade docker-engine
     apt:
         name: docker-engine
         only_upgrade: docker-engine
#         state: latest
```

```
TASK [upgrade docker-engine] ***************************************************
ok: [xx.xx.xx.xx]

```

and if I add state:latest, I just think only_upgrade is not work , because I also can install the latest version without only_upgrade 


在 2016年7月21日星期四 UTC+8下午10:44:46,Kai Stian Olstad写道:
On 21. juli 2016 03:44, richar...@gmail.com wrote:

Kai Stian Olstad

unread,
Jul 28, 2016, 2:58:23 AM7/28/16
to ansible...@googlegroups.com
On 28. juli 2016 07:54, richar...@gmail.com wrote:
> Thanks for you suggestion but I just get this when use you way
>
> ```
> - name: upgrade docker-engine
> apt:
> name: docker-engine
> only_upgrade: docker-engine
> # state: latest
> ```
>
> ```
> TASK [upgrade docker-engine]
> ***************************************************
> ok: [xx.xx.xx.xx]
>
> ```
>
> and if I add state:latest, I just think only_upgrade is not work , because
> I also can install the latest version without only_upgrade

I'm not sure I understand you, my test of only_upgrade

$ dpkg -l htop
dpkg-query: no packages found matching htop

I run this task:
- name: upgrade if exist
apt:
name=htop
state=latest
only_upgrade=true

The output:
TASK [upgrade if exist]
********************************************************
changed: [localhost]

stdout: Reading package lists...
Building dependency tree...
Reading state information...
Skipping htop, it is not installed and only upgrades are requested.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

As you see, nothing was installed and this confirms it

$ dpkg -l htop
dpkg-query: no packages found matching htop

So the only_upgrade is working in Ansible 2.1.0.
The apt module is using the apt-get command and only_upgrade=true adds
--only-upgrade as an option to apt-get.

--
Kai Stian Olstad

richar...@gmail.com

unread,
Jul 28, 2016, 5:00:54 AM7/28/16
to Ansible Project, ansible-pr...@olstad.com
Thank you very much ,

I know it right now ,thank you very much

you get the stdout message used register and debug ??

在 2016年7月28日星期四 UTC+8下午2:58:23,Kai Stian Olstad写道:

Kai Stian Olstad

unread,
Jul 28, 2016, 1:15:48 PM7/28/16
to ansible...@googlegroups.com
On 28. juli 2016 11:00, richar...@gmail.com wrote:
> Thank you very much ,
>
> I know it right now ,thank you very much
>
> you get the stdout message used register and debug ??

No, I use a callback plugin that give a more human readable output.
The one I use is this one
https://github.com/n0ts/ansible-human_log

--
Kai Stian Olstad

richar...@gmail.com

unread,
Jul 28, 2016, 10:40:14 PM7/28/16
to Ansible Project, ansible-pr...@olstad.com
Woo!!   

Thanks a lot

在 2016年7月29日星期五 UTC+8上午1:15:48,Kai Stian Olstad写道:
Reply all
Reply to author
Forward
0 new messages