ansible / ansible-modules-core

Ansible modules - these modules ship with ansible
1.3k stars 1.95k forks source link

yum module appends unwanted data to value of {{ item }} variable #5856

Closed iamtrump closed 7 years ago

iamtrump commented 7 years ago
ISSUE TYPE
COMPONENT NAME

yum module

ANSIBLE VERSION

2.2.0.0.

CONFIGURATION

Default configuration.

OS / ENVIRONMENT

Ansible host: Ubuntu 16.10. Managed host: CentOS 7.

SUMMARY

yum can append unwanted data to variable {{ item }} after using.

STEPS TO REPRODUCE

I tried to run something like this:

tasks:
  - name: Install packages with handlers                                                                                                                                             
    yum: name=/tmp/{{ item }} state=present
    notify: restart {{ item }}
    with_items:
      - ntp-4.2.6p5-22.el7.centos.2.x86_64.rpm

handlers:
  - name: restart ntp-4.2.6p5-22.el7.centos.2.x86_64.rpm
    service: name=ntpd state=restarted enabled=yes
EXPECTED RESULTS

I expected to see something like this:

TASK [Install packages with handlers] ******************************************
changed: [hostname] => (item=ntp-4.2.6p5-22.el7.centos.2.x86_64.rpm)

RUNNING HANDLER [restart ntp-4.2.6p5-22.el7.centos.2.x86_64.rpm] ***************
changed: [hostname]
ACTUAL RESULTS

But actually I've got the following:

TASK [Install packages with handlers] ******************************************
ERROR! The requested handler 'restart [u'/tmp/ntp-4.2.6p5-22.el7.centos.2.x86_64.rpm']' was not found in either the main handlers list nor in the listening handlers list

As you can see "/tmp/" has been appended after first call {{ item }} variable.

chuckyz commented 7 years ago

Jinja2 should be wrapped with quotes (See "Gotchas" on this page http://docs.ansible.com/ansible/YAMLSyntax.html). What occurs when you change your notify line to the following?

notify: "restart {{ item }}"

iamtrump commented 7 years ago

OK, I tried this way and I've got the same: ERROR! The requested handler 'restart [u'/tmp/ntp-4.2.6p5-22.el7.centos.2.x86_64.rpm']' was not found in either the main handlers list nor in the listening handlers list

I'm absolutely sure that it is a yum module bug: I tried the same with copy module and it works as expected:

- name: Copy packages with handlers
  copy: src=/opt/repository/project/7/x86_64/{{ item }} dest=/tmp/{{ item }}
  notify: restart {{ item }}
  with_items:
    - ntp-4.2.6p5-22.el7.centos.2.x86_64.rpm

Output:

TASK [Copy packages with handlers] ******************************************
changed: [hostname] => (item=ntp-4.2.6p5-22.el7.centos.2.x86_64.rpm)

RUNNING HANDLER [restart ntp-4.2.6p5-22.el7.centos.2.x86_64.rpm] ***************
changed: [hostname]
ansibot commented 7 years ago

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide.