In your example of what you're trying to do, you're setting "group" inside
of the template but never returning it to the task.  What you might want is
something like this:

- name: Set Group
  set_fact:
    group: |
      {% if c == 1 %}
      grp1
      {% elif c ==2 %}
      grp3
      {% else %}
      grp4
      {% endif %}

-- Steve

On Mon, Jun 3, 2019 at 12:49 AM Ansar Sahit <sahitan...@gmail.com> wrote:

> Hi All,
>
> Im trying to choose ansible inventory host group conditionally.
>
> - name: Set group
>   set_fact:
>     group: |
>         {% if c == 1 %}
>         {% set group = 'grp1' %}
>         {% elif c == 2 %}
>         {% set group == 'grp3' %}
>         {% else %}
>         {% group == 'grp4' %}
>         {% endif %}
>
> - debug:
>      var=group
>
>
> This doesnt seem to work.
>
> Whats the right way to use if-else with ansible set??
>
> Kinldy assist.
>
> --
> 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-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/de181027-dc27-4190-8d1e-1e5feec12546%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/de181027-dc27-4190-8d1e-1e5feec12546%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFbiokdBbOsnz5nVCMbX-9ouTTL4K8jL2WNoQKz-F-MBYZq0fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to