when condition not being evaluated with include statement

44 views
Skip to first unread message

Imran Khan

unread,
Aug 18, 2014, 7:20:06 AM8/18/14
to ansible...@googlegroups.com
I have a tikitaka3.yml (main yml file) and a tikitaka3a.yml (playbook to be included) . When I prompt the user for a variable and then in the tasks section when I call it, like so:

    ---
    - hosts: all

    vars:
      khan:
    # contents: "{{ lookup('file', '/home/imran/Desktop/tobefetched/file1.txt') }}"

    vars_prompt:
     - name: targetenv
       prompt: 1.)EPC 2.)CLIENTS 3)TESTERS
       private: False
       default: "1"

    gather_facts: no
    tasks:

    - name: Inlude playbook tikitaka3a
    include: /home/khan/Desktop/playbooks/tikitaka3a.yml target=umar
    when: targetenv.stdout|int < 2  #this statement has no effect
    #when: targetenv == 1  #Neither does this statement
    #when: targetenc == "1"  #and neither does this statement have affect
  

    #- name: stuff n stuff # This task will give an error if not commented 
    #  debug: var=targetenv.stdout


The include statement always comes into affect, without the when condition ever being evaluated

Brian Coca

unread,
Aug 18, 2014, 7:44:18 AM8/18/14
to ansible...@googlegroups.com
The when does not affect the include itself, it gets added to all tasks included.​  

Michael DeHaan

unread,
Aug 18, 2014, 8:36:18 AM8/18/14
to ansible...@googlegroups.com
Take a look at the docs of the "group_by" module if you want some more elegant output based on dynamic criteria.



On Mon, Aug 18, 2014 at 7:44 AM, Brian Coca <bria...@gmail.com> wrote:
The when does not affect the include itself, it gets added to all tasks included.​  

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CADn%2BHsz2fUOsaQ0Km6_Shmf3DtRm%2BDsoUdiubLefSuR51WESnQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Imran Khan

unread,
Aug 18, 2014, 8:42:26 AM8/18/14
to ansible...@googlegroups.com
Then what can I do to achieve the functionality that I require?

Imran Khan

unread,
Aug 18, 2014, 8:51:50 AM8/18/14
to ansible...@googlegroups.com
Basically I want to run my secondary playbook on a specific number of hosts in a specific group (I have shown just one example of a group here i.e. umar, I intend on having three groups) using var_prompts, the group is going to be specified in my main file whereas the logic for particular host selection will reside in each of the 3 secondary playbooks for example the user wants to modify the first 3 nodes (from a total of 15) in the group named umar

Michael DeHaan

unread,
Aug 18, 2014, 10:01:50 AM8/18/14
to ansible...@googlegroups.com
The group_by module?


--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Imran Khan

unread,
Aug 19, 2014, 3:49:11 AM8/19/14
to ansible...@googlegroups.com
Well, I think I will just make a predefined number of groups such as EPC1, EPC2 and EPC4 (each containing 1,2 or 4 EPCs) , similarly do the same for CLIENTS and SERVERS and tell the user to modify the hosts at the start of a play book such as 
    - hosts: SERVER1:EPC2:CLIENTS4

This is very inefficient, but I don't know what to do. Can the group-by module do something similar without having to do something that is so inefficient
Reply all
Reply to author
Forward
0 new messages