---
- name: Test when functionality.
hosts: all
tasks:
- name: Output inventory_hostname.
debug:
msg: "The inventory hostname is {{ inventory_hostname }}."
- name: Install httpd
yum:
name: httpd
state: latest
disable_gpg_check: yes
when: ("{{ inventory_hostname }}" in groups["web"]) or ("{{
inventory_hostname }}" in groups["web_backend"])
ignore_errors: true
notify: restart httpd
...
# vim: set ft=ansible:
The syntax for your when statement is incorrect. As noted elsewhere support
for bare variables is deprecated, so you should not be using them anywhere.
The playbook included above shows the correct syntax. Hope that helps.
Best of luck!
Alex
On Wednesday, November 16, 2016 at 9:06:49 AM UTC-8, Steven Smith wrote:
>
> This is the play I am trying to get to run:
>
> - name: Install httpd
> yum: name=httpd state=latest disable_gpg_check=yes
> when: (inventory_hostname in groups["web"]) or (inventory_hostname in
> groups["web_backend"])
> ignore_errors: true
> notify: restart httpd
>
> I get this error:
>
> fatal: [rhel7]: FAILED! => {"failed": true, "msg": "The conditional check
> '(inventory_hostname in groups[\"web\"]) or (inventory_hostname in
> groups[\"web_backend\"])' failed. The error was: error while evaluating
> conditional ((inventory_hostname in groups[\"web\"]) or (inventory_hostname
> in groups[\"web_backend\"])): Unable to look up a name or access an
> attribute in template string ({% if (inventory_hostname in groups[\"web\"])
> or (inventory_hostname in groups[\"web_backend\"]) %} True {% else %} False
> {% endif %}).\nMake sure your variable name does not contain invalid
> characters like '-': argument of type 'StrictUndefined' is not
> iterable\n\nThe error appears to have been in
> '/etc/ansible/roles/httpd/tasks/enabled.yml': line 14, 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- name: Install httpd\n ^ here\n"}
>
> If my hosts file has nothing at all for "web" or "web_backend" I am hoping
> it would just skip over this entire play instead of throwing this big red
> error.
>
> If either one of those are defined, then I want this play to run... can
> anyone please help?
>
--
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/9dd18148-6fdb-45d6-b792-e39f89f68917%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.