Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APT module behavior changed in 2.4 #30638

Closed
kepeket opened this issue Sep 20, 2017 · 4 comments · Fixed by #31577
Closed

APT module behavior changed in 2.4 #30638

kepeket opened this issue Sep 20, 2017 · 4 comments · Fixed by #31577
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_info This issue requires further information. Please answer any outstanding questions. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@kepeket
Copy link

kepeket commented Sep 20, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

modules/packaging/os/apt.py

ANSIBLE VERSION
ansible 2.4.0.0
  config file = /Users/kevin.prettre/work/deploy/ansible.cfg
  configured module search path = [u'/Users/kevin.prettre/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/kevin.prettre/.pyenv/versions/2.7/envs/ansible/lib/python2.7/site-packages/ansible
  executable location = /Users/kevin.prettre/.pyenv/versions/ansible/bin/ansible
  python version = 2.7 (r27:82500, Sep 15 2017, 22:21:11) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]
CONFIGURATION
ANSIBLE_SSH_ARGS(/Users/kevin.prettre/work/deploy/ansible.cfg) = -o ControlMaster=no -o UserKnownHostsFile=/dev/null
ANSIBLE_SSH_RETRIES(/Users/kevin.prettre/work/deploy/ansible.cfg) = 2
DEFAULT_CALLBACK_WHITELIST(/Users/kevin.prettre/work/deploy/ansible.cfg) = ['profile_tasks']
DEFAULT_FORKS(/Users/kevin.prettre/work/deploy/ansible.cfg) = 15
DEFAULT_GATHERING(/Users/kevin.prettre/work/deploy/ansible.cfg) = explicit
HOST_KEY_CHECKING(/Users/kevin.prettre/work/deploy/ansible.cfg) = False
OS / ENVIRONMENT

Running from: Darwin - MacOS Serria 10.12.6 (16G29) OR debian jessie (Python 2.7)
Targeting: Debian jessie (Python 2.7.9)
apt 1.0.9.8.4
aptitude 0.6.11-1+b1
dpkg 1.17.27

SUMMARY

package_is_installed = fnmatch.fnmatch(installed_version, version)

if (not installed and not only_upgrade) or (upgrade and upgradable):
pkg_list.append("'%s'" % package)
if installed and upgradable and version:
# This happens when the package is installed, a newer version is
# available, and the version is a wildcard that matches both
#
# We do not apply the upgrade flag because we cannot specify both
# a version and state=latest. (This behaviour mirrors how apt
# treats a version with wildcard in the package)
pkg_list.append("'%s'" % package)

since the release of 2.4, that particular ligne, combined with lines from 494 to 503 (in the same file) leads to a wrong behavior of the apt module

STEPS TO REPRODUCE
# playbooks/nginx.yaml
 ---
 - hosts: webserver01
    name: install nginx
    tasks:
    - apt:
         name: nginx={{version}}
         state: installed
         update_cache: yes
         only_upgrade: yes
         force: yes

$ ansible-playbook playbooks/nginx.yml --extra-vars version="1.12.1-1~dotdeb+8.1"

EXPECTED RESULTS

Let's nginx 1.6.2-5+deb8u5 is intalled and I want to upgrade to 1.12.1-1~dotdeb+8.1

The playbook should detect that the package is installed, that the version installed mismatches the version requested, and install the newer version.

BUT, according to line 384, package_installed = fnmatch.fnmatch(installed_version, version) which is always False when you want to install a specific version.

You can reproduce this if clause on the target machine quite easily in a python console

>>> import apt
>>> import fnmatch
>>> cache = apt.Cache()
>>> pkg = cache['nginx']
>>> ll_pkg = cache._cache['nginx']
>>> installed = ll_pkg.current_state == 6 # that's apt_pkg.CURSTATE_INSTALLED value
>>> print(installed)
True
>>> cur_version = pkg.installed.version
>>> print(cur_version)
1.6.2-5+deb8u5
>>> target_version = '1.12.1-1~dotdeb+8.1'
>>> print(target_version)
1.12.1-1~dotdeb+8.1
>>> package_is_installed = fnmatch.fnmatch(cur_version, target_version)
>>> print(package_is_installed)
False
>>> print(fnmatch.fnmatch(cur_version, '*'))
True

TASK [install nginx] ***************************************************************************************************************
Wednesday 20 September 2017 16:08:29 +0200 (0:00:00.029) 0:00:00.029 ***
changed: [webserver01]

And nginx installed in it's newer version

ACTUAL RESULTS
TASK [install nginx] ***************************************************************************************************************
Wednesday 20 September 2017  16:08:29 +0200 (0:00:00.029)       0:00:00.029 ***
ok: [webserver01]

nginx version did not change

Thanks for you work, I'll stick in 2.3 for now.

Bye.

@ansibot
Copy link
Contributor

ansibot commented Sep 20, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 20, 2017
@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Sep 22, 2017
@manderson-it
Copy link
Contributor

The version is not part of the package name. See apt-cache show nginx. They are two separate meta data "Package:" and "Version:". Can't you achieve your desired result with "state: latest"?

@kepeket
Copy link
Author

kepeket commented Sep 28, 2017

Hi,

I'm expecting to pin-point a specific version, that's the goal of my playbook.

I've debug print the whole process, and I can assure you that you can't move to a specific version of an installed package anymore.

@mkrizek
Copy link
Contributor

mkrizek commented Mar 14, 2018

@kepeket can you please test if #31577 fixes your issue? Thanks!

@mkrizek mkrizek added the needs_info This issue requires further information. Please answer any outstanding questions. label Mar 19, 2018
ppanczyk added a commit to ppanczyk/ansible that referenced this issue Apr 10, 2018
mkrizek pushed a commit to mkrizek/ansible that referenced this issue Apr 17, 2018
ilicmilan pushed a commit to ilicmilan/ansible that referenced this issue Nov 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_info This issue requires further information. Please answer any outstanding questions. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants