fatal error when skipping includes

57 views
Skip to first unread message

senorsmile

unread,
Aug 13, 2015, 6:55:05 PM8/13/15
to Ansible Project
Error: 
fatal: [myhost] => with_items expects a list or a set

I have a role with the following tasks(snippets included): 
tasks/main.yml
---
- include: server.yml
 
when: icinga_install_mode == 'server'


tasks/server.yml
---
.....
- name: Get filenames
  connection
: local
  shell
: find ./roles/rolename/templates/custom2/.....
 
register: the_files


- name: Sync files
 
template:
    src
: "custom2/{{ item }}.j2"
    dest
: "/etc/bla/{{ item }}"
  with_items
: "{{ the_files.stdout_lines | list }}"
.....


It happily skips every other task (although it shows quite a detailed list of what it would have run and seems to take up WAY to much time processing tasks before it gets to this error.  

How do I actually skip that include and NOT process anything within it?

Brian Coca

unread,
Aug 13, 2015, 8:22:35 PM8/13/15
to Ansible Project
the include itself is not skippable, the when gets added to the included tasks.




--
Brian Coca

senorsmile

unread,
Aug 13, 2015, 8:26:57 PM8/13/15
to Ansible Project
I'm not sure I follow you.  The include is being skipped since the when: condition isn't met.  All other tasks above the one that errs out shows skipped.  It's just that specific task that makes everything fail for that host.  

I have attempted to add a 'default' filter to the when:, but it seems like it is always defined, even though it's being skipped ?!?!?

Brian Coca

unread,
Aug 13, 2015, 8:46:11 PM8/13/15
to Ansible Project
try:
with_items: "{{ ((the_files|default([])).stdout_lines|default([])) | list }}"


--
Brian Coca

senorsmile

unread,
Aug 13, 2015, 9:09:06 PM8/13/15
to Ansible Project
Ah, great catch.  That actually works.  

Now, to convince ansible not to evaluate anything in included files which are skipped...

senorsmile

unread,
Aug 19, 2015, 12:47:04 PM8/19/15
to Ansible Project
And I've run into this bug yet again!

I have the following which fails on skipped hosts: 

- name: Check all other host certs
  connection: local
  sudo: false
  stat:  
    path: "{{ role_path }}/templates/ca/{{ item }}.crt"
   with_items: "{{ (nagios_host_fqdns_flat|default([])).split(',')|default([]) }}"
  register: stat_host_certs

This is becoming quite time consuming to insert for every with_* on skipped files!!!

senorsmile

unread,
Aug 19, 2015, 1:02:30 PM8/19/15
to Ansible Project
@Brian, 

According to your comment in this issue: 
https://github.com/ansible/ansible/issues/11961

the when: of the include: gets run AFTER the with_xxx of the child file?  This doesn't make any sense to me.  If you are conditionally including a file, NOTHING in that file should be processed.  I am not being combative, but am I missing something here?  That seems like a real bug; the specific bug that I'm running into over and over again. 

Serge van Ginderachter

unread,
Aug 19, 2015, 1:09:32 PM8/19/15
to ansible...@googlegroups.com

On 19 August 2015 at 19:02, senorsmile <senor...@gmail.com> wrote:
the when: of the include: gets run AFTER the with_xxx of the child file?  This doesn't make any sense to me.  If you are conditionally including a file, NOTHING in that file should be processed.  I am not being combative, but am I missing something here?  That seems like a real bug; the specific bug that I'm running into over and over again. 


​You are not conditionally including. you are applying the condition to all tasks in the include.

senorsmile

unread,
Aug 19, 2015, 1:20:38 PM8/19/15
to Ansible Project
Ahhhh!  Thanks Serge.  So it is applying in the same manner as roles apply args (e.g. tags: ).  

So, now to figure out how to default a split().  

senorsmile

unread,
Aug 19, 2015, 5:08:10 PM8/19/15
to Ansible Project
Ultimately fixed this by simply putting this into the role's defaults/main.yml

nagios_host_fqdns_flat: ([])
Reply all
Reply to author
Forward
0 new messages