Re: [ansible-project] Win_reg_stat - set_fact problem with missing dict key

2017-12-11 Thread Gareth Stockdale
Thanks Kai.

Apologise for the code presentation, I was typing from my phone.  However your 
point 3 was the winner!  

Thank you.

-- 
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/ad29c985-3bcc-48d0-b6bc-53fdba195c4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Win_reg_stat - set_fact problem with missing dict key

2017-12-11 Thread Kai Stian Olstad
On Monday, 11 December 2017 15.26.58 CET Gareth Stockdale wrote:
> So new to ansible.  I am using win_reg_stat to lookup registry keys to 
> ultimately uninstall some software.  If the reg entry is found, myvar.value ( 
> after defining "register: myvar") contains the registry value.  If it is not 
> found, that key is not defined in the myvar dict.  
> 
> Problem I have is that I cannot use below in both cases as if they key does 
> not exist, it fails with Ansible defined variable error
> 
> Set_fact:
>Thisvar: {{ myvar.value }}
>When: myvar.value is defined
> 
> I have tried a when: clause with is/is not defined, but the presence of the 
> .value key in the setting of the variable/fact name causes failure.  I would 
> of thought (or liked to think), the when condition would prevent the setting 
> and thus check of the undefined variable.
> 
> Any thoughts?

You have three problems, set_fact and when is all lower case.
When you have curly brackets after colon you need quotes around it.
Your When becomes a variable since it is indented to far in, when must be on 
the task, indented the same as set_fact.

- set_fact:
Thisvar: '{{ myvar.value }}'
  when: myvar.value is defined


-- 
Kai Stian Olstad

-- 
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/3014117.xHCaCqcJ6J%40x1.
For more options, visit https://groups.google.com/d/optout.