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

Ansible2 : roles and with_items #12623

Closed
Ekleog opened this issue Oct 4, 2015 · 4 comments
Closed

Ansible2 : roles and with_items #12623

Ekleog opened this issue Oct 4, 2015 · 4 comments

Comments

@Ekleog
Copy link

Ekleog commented Oct 4, 2015

Issue Type:

Bug Report

Ansible Version:
ansible 2.0.0 (devel a89412ecb1) last updated 2015/09/29 21:45:10 (GMT +200)
  lib/ansible/modules/core: (detached HEAD a4ac171a07) last updated 2015/09/30 02:14:07 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 3c8c716801) last updated 2015/09/30 02:14:07 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  configured module search path = None

Also tested with v2.0.0-0.2-alpha2 ; I can test with any other version of your choice.

Ansible Configuration:

I changed #!/usr/bin/env python to /usr/bin/env python2 in ansible-playbook.

Changes to /etc/ansible/ansible.cfg ; excluding comment-only hunks, result of diff /etc/ansible/ansible.cfg examples/ansible.cfg:

81c92,94
< ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}

---
> #ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
> # This short version is better used in templates as it won't flag the file as changed every run.
> ansible_managed = Ansible managed: {file} on {host}
115,120c128,134
< action_plugins     = /usr/share/ansible_plugins/action_plugins
< callback_plugins   = /usr/share/ansible_plugins/callback_plugins
< connection_plugins = /usr/share/ansible_plugins/connection_plugins
< lookup_plugins     = /usr/share/ansible_plugins/lookup_plugins
< vars_plugins       = /usr/share/ansible_plugins/vars_plugins
< filter_plugins     = /usr/share/ansible_plugins/filter_plugins

---
> #action_plugins     = /usr/share/ansible/plugins/action
> #callback_plugins   = /usr/share/ansible/plugins/callback
> #connection_plugins = /usr/share/ansible/plugins/connection
> #lookup_plugins     = /usr/share/ansible/plugins/lookup
> #vars_plugins       = /usr/share/ansible/plugins/vars
> #filter_plugins     = /usr/share/ansible/plugins/filter
> #test_plugins       = /usr/share/ansible/plugins/test
Environment:

Running on Archlinux, managing using local connection.

Summary:

I am trying to write a role that uses with_items along with roles, with Ansible 2. Unfortunately, the item variable does not seem exported.

Steps To Reproduce:

Try running the following playbook, that includes a dummy role.

File vpnclients.yml

---
- hosts: vpnclients
  roles:
    - role: openvpn-client
      openvpn_client_server: "{{ item }}"
      with_items: "{{ groups['vpnservers'] }}"

File roles/openvpn-client/tasks/main.yml

---
- debug: msg='calling for server {{ openvpn_client_server }}'
Expected Results:

Without the {{ openvpn_client_server }} part, I get the expected calling for server output.

Actual Results:

Instead, with the {{ openvpn_client_server }} part, I get the following error message:

fatal: [hostname]: FAILED! => {"failed": true, "msg": "ERROR! ERROR! 'item' is undefined"}
@jimi-c
Copy link
Member

jimi-c commented Oct 4, 2015

@Ekleog this is not supported syntax. You cannot use with_ loops on roles in this manner, and any loops should be done within the role.

If you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!

@jimi-c jimi-c closed this as completed Oct 4, 2015
@skinlayers
Copy link

@jimi-c According to ansible-example/language_features/roletest2.yml, this should be supported. Any idea if this worked at one point, but was later removed? We should probably update the example if that's the case.

https://github.com/ansible/ansible-examples/blob/master/language_features/roletest2.yml

@PumpkinSeed
Copy link

I got the same problem, and I found this: http://rogersherman.com/a-simple-how-to-passing-a-loop-to-an-ansible-role/

@aboyett
Copy link

aboyett commented Jun 22, 2016

@skinlayers that example using with_items was modified the day after @PumpkinSeed's comment in commit ansible/ansible-examples@f72887a
though the comment, https://github.com/ansible/ansible-examples/blob/f72887ab1b762363c89392fb56c4d6569c5893c9/language_features/roletest2.yml#L35-L36 no longer makes sense after the modification

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants