ansible / ansible-modules-core

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

set_facts with with_items fails to template the last item #5836

Closed ZeiP closed 7 years ago

ZeiP commented 7 years ago
ISSUE TYPE
COMPONENT NAME

set_facts

ANSIBLE VERSION
ansible 2.2.0.0
CONFIGURATION
OS / ENVIRONMENT

Fedora 25

SUMMARY

When using a set_facts task with with_items to loop through a list and create a new list, the last item handled is not templated properly which makes the list unusable.

STEPS TO REPRODUCE
---
- set_fact:
    nginx_vhosts: []
  tags: minimal_debug

- name: Define variable
  set_fact:
    nginx_vhosts: >
      {{ nginx_vhosts + [ { 'listen': "8080 default_server", 'server_name': "{{ site.site_domain }}", 'root': "/srv/www/{{ site.site_domain }}/current", 'index': "index.php"  } ] }}
  with_items:
    - [{'site_domain': "example.org", 'site_name': "example"}]
    - [{'site_domain': "example.org", 'site_name': "example"}]
    - [{'site_domain': "example.org", 'site_name': "example"}]
  loop_control:
    loop_var: site
  tags: minimal_debug

- debug: "{{ nginx_vhosts }}"
  tags: minimal_debug
EXPECTED RESULTS

[ { 'listen': "8080 default_server", 'server_name': "example.org", 'root': "/srv/www/example.org/current", 'index': "index.php" }, { 'listen': "8080 default_server", 'server_name': "example.org", 'root': "/srv/www/example.org/current", 'index': "index.php" } , { 'listen': "8080 default_server", 'server_name': "example.org", 'root': "/srv/www/example.org/current", 'index': "index.php" } ]

ACTUAL RESULTS
TASK [drupal_be : debug] *******************************************************
task path: /home/.../vcs/drupal-ansible/roles/drupal_be/tasks/main.yml:220
fatal: [.fi]: FAILED! => {
    "failed": true, 
    "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: [{'index': u'index.php', 'root': u'/srv/www/example.org/current', 'server_name': u'example.org', 'listen': u'8080 default_server'}, {'index': u'index.php', 'root': u'/srv/www/example.org/current', 'server_name': u'example.org', 'listen': u'8080 default_server'}, {'index': u'index.php', 'root': u'/srv/www/{{ site.site_domain }}/current', 'server_name': u'{{ site.site_domain }}', 'listen': u'8080 default_server'}]: 'site' is undefined\n\nThe error appears to have been in '/home/.../tasks/main.yml': line 220, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug: \"{{ nginx_vhosts }}\"\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.  Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"
}
ansibot commented 7 years ago

@ansible ping, this issue is waiting for your response. click here for bot help

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. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

ZeiP commented 7 years ago

This issue was moved to ansible/ansible#19177