@Karl you have correctly understood my requirement. 

However, can you propose a solution with vars instead of using set_fact ?

On Wednesday, September 11, 2019 at 9:58:58 PM UTC+5:30, Karl Auer wrote:
>
> If I understand correctly you have a variable called fRegion that contains 
> a value.
>
> You want to change that variable to contain the string "'prd' OR region 
> LIKE 'dr'" if the variable initially contains either the value 
> "prd_or_dr" or the value "dr_or_prd".
>
> - set_fact:
>      fRegion: "'prd' OR region LIKE 'dr'"
>   when: fRegion == 'prd_or_dr' or fRegion == 'dr_or_prod'
>
> The problem with doing this is that you have lost the original value of 
> fRegion now. And you are IMHO misusing the variable; a variable should in 
> general either be a control variable (one that controls program flow) or 
> data. Using the same variable to contain both control information and data 
> at different times is confusing and leads to error. This would be nicer:
>
> - set_fact:
>      sqlFragment: "'some default value'"
>    
> - set_fact:
>      sqlFragment: "'prd' OR region LIKE 'dr'"
>   when: fRegion == 'prd_or_dr' or fRegion == 'dr_or_prd'
>
> Then it is completely clear that you are testing fRegion to find out what 
> yor SQL fragment should be.
>
> Regards, K.
>
> On Thu, Sep 12, 2019 at 2:03 AM Mohtashim S <mohta...@gmail.com 
> <javascript:>> wrote:
>
>> @Dick hi, 
>>
>> We can definitely use a different variable here 
>>
>> fRegion: "'prd' OR region LIKE 'dr'"
>>
>> I wanted to have less variables hence kept it the same. 
>>
>> The variable is used in a complex SQL query that is run by my playbook 
>> and as we know SQL queries need single quotes (')
>>
>> Thus, the fRegion variable or any other should be assigned the string 
>> which will embed in the SQL query to get it to work. 
>>
>> On Wednesday, September 11, 2019 at 9:16:14 PM UTC+5:30, Dick Visser 
>> wrote:
>>>
>>> I am truly confused about the logic. 
>>> You’re trying to set a variable based on itself, OR itself?
>>>
>>> Could you maybe explain what you are trying to achieve?
>>>
>>> Even within this information I would definitely restructure things...
>>>
>>>
>>> Dick 
>>>
>>>
>>>
>>> On Wed, 11 Sep 2019 at 13:02, Mohtashim S <mohta...@gmail.com> wrote:
>>>
>>>> I pass a variable fRegion to my ansible playbook. 
>>>>
>>>> I wish to set fRegion  to this string ->  'prd' OR region LIKE 'dr'
>>>>
>>>> if the passed value is either "prd_and_dr" or "dr_and_prd".
>>>>
>>>> I call the playbook like this :
>>>>
>>>> ansible-playbook  site.yml -e "fRegion=dr_and_prd"
>>>>
>>>> Here is my attempted playbook that does not help.
>>>>
>>>> - name: "Play 1-Find the details here"
>>>>
>>>>
>>>>   hosts: localhost
>>>>   any_errors_fatal: True
>>>>   vars:
>>>>
>>>>
>>>>     fRegion: "'prd' OR region LIKE 'dr'"
>>>>     when: fRegion == "prd_and_dr" or fRegion == "dr_and_prd"
>>>>     ansible_ssh_extra_args: -o StrictHostKeyChecking=no
>>>>
>>>>
>>>>     debug:
>>>>       msg: "{{ fRegion }}"
>>>>
>>>>
>>>> Can you please suggest ?
>>>>
>>>> -- 
>>>> 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...@googlegroups.com.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/ansible-project/7c6887c0-0579-45b0-bba4-835461f2401a%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/ansible-project/7c6887c0-0579-45b0-bba4-835461f2401a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> -- 
>>> Sent from a mobile device - please excuse the brevity, spelling and 
>>> punctuation.
>>>
>> -- 
>> 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...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/6565d2f2-c129-4b0b-9046-34a695f86107%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/6565d2f2-c129-4b0b-9046-34a695f86107%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Karl Auer
>
> Email  : ka...@2pisoftware.com <javascript:>
> Website: http://2pisoftware.com
>
> GPG/PGP : 301B 1F4E 624D AD99 242C 7A68 EC24 7113 E854 4A4E
> Previous: 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5e626309-2a35-4901-ae1d-cea12850d4df%40googlegroups.com.

Reply via email to