How to define variable based on when condition

16 views
Skip to first unread message

sase kumar

unread,
Jun 25, 2019, 12:58:01 PM6/25/19
to Ansible Development
Hi Folks,

I'm new to ansible and I have got some confusion in when the statement

here is my playbook - 

 hosts: localhost
  gather_facts: false
  vars:
   nodetype: "DI"
  tasks:
  - name: concatenate
    set_fact:
     argu: "DI=1,DC=0,DP=0"
    when:  "{{ nodetype }}" == "DI"
    register: argu
    set_fact:
     argu: "DI=0,DC=1,DP=0"
    when: "{{ nodetype }}" == "DC"
    register: argu
  - debug:
     msg: "{{ argu }}"

This is just defining variable "argu" based on when condition ,I want to just build variable based on the input nodetype . but this is not working and always it prints the second argu(DI=0,DC=1,DP=0) value

Is this the right way or simpler way to achieve this?

Matt Martz

unread,
Jun 25, 2019, 1:12:33 PM6/25/19
to sase kumar, Ansible Development
Remove the `register` on those tasks. `set_fact` doesn't need this.

--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/64b662ea-2889-4918-a2bc-b19fcb6e3927%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

sase kumar

unread,
Jun 25, 2019, 1:17:35 PM6/25/19
to Ansible Development
Hi Matt

I removed and tried it , but still it prints the second value of argu in debug msg even though i passed another value
To unsubscribe from this group and stop receiving emails from it, send an email to ansibl...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages