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

yum module fails with 'dict object' has no attribute '\\x00$' when used in loop and with dict lookup #15649

Closed
mmilata opened this issue Apr 28, 2016 · 7 comments · Fixed by #15825
Assignees
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release packaging Packaging category
Milestone

Comments

@mmilata
Copy link

mmilata commented Apr 28, 2016

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
ansible 2.2.0 (devel f2980fc565) last updated 2016/04/28 14:44:57 (GMT +000)
  lib/ansible/modules/core: (detached HEAD e78ee3b128) last updated 2016/04/28 14:46:09 (GMT +000)
  lib/ansible/modules/extras: (detached HEAD ca310f3d15) last updated 2016/04/28 14:46:13 (GMT +000)
  config file = 
  configured module search path = Default w/o overrides
CONFIGURATION

No configuration.

OS / ENVIRONMENT

Reproduced on Fedora 23. I'm connecting to localhost, however the error happens before connection attempt is made.

SUMMARY

Running the attached playbook produces the rather cryptic error 'dict object' has no attribute '\\x00$'. The bug appears to be related to:

  • yum module (dnf, apt too),
  • loops,
  • dictionary lookup in the name argument to the module,

as taking any out of the equation does not reproduce the error.

STEPS TO REPRODUCE

Run following playbook:


---
- hosts: all
  gather_facts: false
  vars:
    package_map:
      foo: bar
    packages:
    - foo
  tasks:
  - yum: name={{ package_map[item] }}
    with_items: "{{ packages }}"

ansible-playbook -i hosts reproduce.yml -vvvv

EXPECTED RESULTS

Package bar to be installed using yum.

ACTUAL RESULTS
No config file found; using defaults
Loaded callback default of type stdout, v2.0

PLAYBOOK: reproduce.yml ********************************************************
1 plays in reproduce.yml

PLAY [all] *********************************************************************

TASK [yum] *********************************************************************
task path: /home/fedora/ansible-reproducer/reproduce.yml:12
fatal: [localhost]: FAILED! => {"failed": true, "msg": "'dict object' has no attribute '\\x00$'"}

NO MORE HOSTS LEFT *************************************************************
        to retry, use: --limit @reproduce.retry

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1   
@kustodian
Copy link
Contributor

This shouldn't be closed, since this bug report isn't a bug in the yum module, but in core. This was also introduced with 2.1 because of item squashing changes. Everything worked in versions <=2.0.

@nitzmahone nitzmahone reopened this May 4, 2016
@abadger abadger added bug_report P2 Priority 2 - Issue Blocks Release labels May 5, 2016
@abadger abadger added this to the 2.1.0 milestone May 5, 2016
@abadger
Copy link
Contributor

abadger commented May 5, 2016

After having looked at the associated PR and this bug... the bug itself could be fixed by having a try: except around squashing. If any exceptions are thrown, do not squash. That's a simple change because squashing is simply an optimization (one that we're discussing whether to deprecate since users can give the field a list [ using filters to construct the list if necessary ] instead of relying on squashing).

This is probably a good thing to do regardless of whether we accept that PR as there could be other cornercases i nthe squashing code and we can recover from any of those in the same manner.

willthames added a commit to willthames/ansible that referenced this issue May 6, 2016
* Allow variables that contain a dict lookup
* Squash names built from dictionary values e.g.

  ```
  package: name="{{item.name}}-{{item.version}}"
  with_items:
  - name: hello
    version: 1.2.3
  - name: goodbye
    version: 2.3.4
  ```

  now works the same as

  ```
  package: name="{{item}}"
  with_items:
  - hello-1.2.3
  - goodbye-2.3.4
  ```

* Fix some erroneous test assumptions e.g.

  ```
  package: name="{{pkg_mgr}}"
  with_items:
  - hello-1.2.3
  - goodbye-2.3.4
  ```

  should just install a single package with
  the name pkg_mgr (in effect item is not a bound variable)

Fixes ansible#15649
Reordered some tests to better reflect comments
@abadger abadger self-assigned this May 12, 2016
abadger added a commit to abadger/ansible that referenced this issue May 12, 2016
abadger added a commit that referenced this issue May 12, 2016
…ems loop.

Also add more squashing testcases

Fixes #15649
abadger added a commit that referenced this issue May 12, 2016
…ems loop.

Also add more squashing testcases

Fixes #15649
@szjur
Copy link

szjur commented May 21, 2016

Hi

I had this task in my role that worked perfectly in 1.8.4 and with 2.0.2 it spat out 'dict object' has no attribute '\x00$'.
- name: Install lastest version of the same grsec kernel that is already installed apt: name=linux-image-{{grsecurity.latest_kernel_versions[item]}}-{{item}} state=installed update_cache=yes cache_valid_time=180 force=no install_recommends=no
when: grsecurity_proc.stat.exists and ansible_kernel|match(".*-{{item}}$")
with_items:
- flavour1
- flavour2
- flavour3
register: grsec_kernel

The vars used above were stored in the defaults:

latest_grsec_kernel_version: '3.14.70-1'
grsecurity: {
....
latest_kernel_versions: {
flavour1: "{{latest_grsec_kernel_version}}",
flavour2: "{{latest_grsec_kernel_version}}",
flavour3: "{{latest_grsec_kernel_version}}",
}
}

With de3f013 the error stopped appearing but it didn't install any package either (it was coloured green indicating no changes were done and indeed no package was installed).

Amazingly it works this way in stock 2.0.2 (without the above patch):

- name: Install lastest version of the same grsec kernel that is already installed apt: name=linux-image-{{grsecurity.latest_kernel_versions[item.flavour]}}-{{item.flavour}} state=installed update_cache=yes cache_valid_time=180 force=no install_recommends=no
when: grsecurity_proc.stat.exists and ansible_kernel|match(".*-{{item.flavour}}$")
with_items:
- { flavour: flavour1 }
- { flavour: flavour1 }
- { flavour: flavour1 }
register: grsec_kernel

Is it just me misusing 2.0.2 or it works not the way you intended? Some simpler cases using with_items: seem to work with non-dict-style items. I guess that it is this dict being used here that gives ansible a headache: {{grsecurity.latest_kernel_versions[item]}}-{{item}}.

@abadger
Copy link
Contributor

abadger commented May 21, 2016

@szjur Can you apply this commit in addition to de3f013 and let us know if it works: b75895d ?

I think what's happening is that the squashing function modifies the task.args in addition to returning the new list of squashed values. The fix I applied earlier returned the original list of values in case of an error but did not restore the task.args. This should fix that.

I did something similar to what you're doing with dnf and it errored for me. I think with apt, you're specifying update_cache so it's silently updating the cache and nothing else instead of explicitly throwing an error.

@abadger abadger reopened this May 21, 2016
@szjur
Copy link

szjur commented May 21, 2016

I applied b75895d on top of de3f013 and it now works again with non-dict items :-) I will remove my workaround from the playbook then as I like to keep things simple. Thanks!

@abadger
Copy link
Contributor

abadger commented May 22, 2016

Excellent. The fix ha sbeen merged to the stable-2.1 branch and devel. We'll most likely get it into 2.1.0 but will decide on Monday (it will be in 2.1.1 if it doesn't make it into 2.1.0)

@abadger
Copy link
Contributor

abadger commented Jun 13, 2016

This fix made it into 2.1.0. Closing ticket.

@abadger abadger closed this as completed Jun 13, 2016
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@dagwieers dagwieers added the packaging Packaging category label Mar 3, 2019
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release packaging Packaging category
Projects
None yet
7 participants