Hi,

This E-mail is a little bit old but I am in the same situation.

     ignore_errors: test_err | bool

doesn't work for me on ansible 1.8.4

Is there any work around?

Thank you,
WAKAYAMA Shirou


2014-10-08 1:58 GMT+09:00 Yasir Saleem <[email protected]>:
> I tried few combinations:
>
> #####
> - hosts: jump
>   remote_user: deploy
>   gather_facts: yes
>   tasks:
>     - set_fact: test_err=yes
>     - debug: var=test_err
>     - debug: var=test_err
>       ignore_errors: test_err | bool
> #####
>
> or
>
> ####
> - hosts: jump
>   remote_user: deploy
>   gather_facts: yes
>   tasks:
>     - set_fact: test_err={{ 'yes' |bool }}
>     - debug: var=test_err
>     - debug: var=test_err
>       ignore_errors: test_err
> ####
> or
>
> ####
> - hosts: jump
>   remote_user: deploy
>   gather_facts: yes
>   tasks:
>     - set_fact: test_err=True
>     - debug: var=test_err
>     - debug: var=test_err
>       ignore_errors: test_err
> ####
>
> In all cases got following error:
>
> ####
> PLAY [jump]
> *******************************************************************
>
> GATHERING FACTS
> ***************************************************************
> ok: [qactld1-jump]
>
> TASK: [set_fact test_err=True]
> ************************************************
> ok: [qactld1-jump]
>
> TASK: [debug var=test_err]
> ****************************************************
> ok: [qactld1-jump] => {
>     "test_err": "True"
> }
>
> TASK: [debug var=test_err]
> ****************************************************
> ERROR: error while evaluating conditional: test_err
> ######
>
>
> On Tuesday, October 7, 2014 10:57:16 AM UTC-4, Michael Peters wrote:
>>
>> You are setting test_err to the *string* yes, but ingore_errors is
>> looking for a boolean expression. Also, you don't need to using the
>> "{{ }}" syntax in ignore_errors since it is already using jinja2. Try
>> using the "bool" filter:
>>
>> - hosts: jump
>>   remote_user: deploy
>>   gather_facts: yes
>>   tasks:
>>     - set_fact: test_err=yes
>>     - debug: var=test_err
>>       ignore_errors: test_err | bool
>>
>>
>>
>> On Tue, Oct 7, 2014 at 10:51 AM, Yasir Saleem <[email protected]> wrote:
>> > I am setting test_err to 'yes' via set_fact:
>> >
>> > below is playbook details:
>> >
>> > ######
>> > - hosts: jump
>> >   remote_user: deploy
>> >   gather_facts: yes
>> >   tasks:
>> >     - set_fact: test_err=yes
>> >     - debug: var=test_err
>> >     - debug: var=test_err
>> >       ignore_errors: "{{ test_err }}"
>> >
>> > ####
>> >
>> > output of above playbook:
>> >
>> > ######
>> > PLAY [jump]
>> > *******************************************************************
>> >
>> > GATHERING FACTS
>> > ***************************************************************
>> > ok: [qactld1-jump]
>> >
>> > TASK: [set_fact test_err=yes]
>> > *************************************************
>> > ok: [qactld1-jump]
>> >
>> > TASK: [debug var=test_err]
>> > ****************************************************
>> > ok: [qactld1-jump] => {
>> >     "test_err": "yes"
>> > }
>> >
>> > TASK: [debug var=test_err]
>> > ****************************************************
>> > Traceback (most recent call last):
>> >   File "/usr/local/bin/ansible-playbook", line 309, in <module>
>> >     sys.exit(main(sys.argv[1:]))
>> >   File "/usr/local/bin/ansible-playbook", line 249, in main
>> >     pb.run()
>> >   File "/Library/Python/2.7/site-packages/ansible/playbook/__init__.py",
>> > line 339, in run
>> >     if not self._run_play(play):
>> >   File "/Library/Python/2.7/site-packages/ansible/playbook/__init__.py",
>> > line 695, in _run_play
>> >     if not self._run_task(play, task, False):
>> >   File "/Library/Python/2.7/site-packages/ansible/playbook/__init__.py",
>> > line 468, in _run_task
>> >     task.ignore_errors =  utils.check_conditional(cond , play.basedir,
>> > task.module_vars, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR)
>> >   File "/Library/Python/2.7/site-packages/ansible/utils/__init__.py",
>> > line
>> > 254, in check_conditional
>> >     conditional = template.template(basedir, conditional, inject,
>> > fail_on_undefined=fail_on_undefined)
>> >   File "/Library/Python/2.7/site-packages/ansible/utils/template.py",
>> > line
>> > 115, in template
>> >     varname = template_from_string(basedir, varname, vars,
>> > fail_on_undefined)
>> >   File "/Library/Python/2.7/site-packages/ansible/utils/template.py",
>> > line
>> > 357, in template_from_string
>> >     res = jinja2.utils.concat(rf)
>> >   File "<template>", line 8, in root
>> >   File "/Library/Python/2.7/site-packages/jinja2/runtime.py", line 485,
>> > in
>> > _fail_with_undefined_error
>> >     raise self._undefined_exception(hint)
>> > jinja2.exceptions.UndefinedError: 'test_err' is undefined
>> >
>> > ########
>> >
>> > Reason we are trying to use ignore_errors via variable is because we are
>> > using our own module to run 'cucumber' tests in a role, we want to give
>> > control via variable weather to stop execution upon failures to the role
>> > user. Because in case tests are run in CI ( via jenkins) we want jenkins
>> > plugin to compile results, for command line users, ansible console we
>> > will
>> > have control.
>> >
>> > I hope this clarifies.
>> >
>> > Thanks,
>> > Yasir.
>> >
>> > On Tuesday, October 7, 2014 10:10:11 AM UTC-4, Mark wrote:
>> >>
>> >> Hi Yasir,
>> >>
>> >> Have you read through:
>> >> http://docs.ansible.com/playbooks_error_handling.html  ?
>> >>
>> >> Ignore_errors is taking yes or no, because simply put there isn't any
>> >> other answer possible to "Do you want me to ignore the errors?" yes/no.
>> >> You
>> >> are answering with "Mooo" and the system doesnt speak cowish, yet
>> >> I'm interested in knowing why do you want to let ignore_errors take a
>> >> variable?
>> >>
>> >> Regards,
>> >> Mark
>> >>
>> >>
>> >>
>> >>
>> >> On Monday, October 6, 2014 7:22:18 PM UTC+2, Yasir Saleem wrote:
>> >>>
>> >>> Hi,
>> >>>    I was trying to use ignore_errors to take a variable, but it fails.
>> >>>
>> >>> Here is example play for ignore error not working:
>> >>>
>> >>> - hosts: jump
>> >>>   remote_user: deploy
>> >>>   gather_facts: yes
>> >>>   tasks:
>> >>>     - set_fact: test_err=yes
>> >>>     - debug: var=test_err
>> >>>       ignore_errors: "{{ test_err }}"
>> >>>
>> >>> output was:
>> >>>
>> >>> #############
>> >>> PLAY [jump]
>> >>> *******************************************************************
>> >>>
>> >>> GATHERING FACTS
>> >>> ***************************************************************
>> >>> ok: [qa10-jump1]
>> >>>
>> >>> TASK: [set_fact test_err=yes]
>> >>> *************************************************
>> >>> ok: [qa10-jump1]
>> >>>
>> >>> TASK: [debug var=test_err]
>> >>> ****************************************************
>> >>> Traceback (most recent call last):
>> >>>   File "/usr/local/bin/ansible-playbook", line 309, in <module>
>> >>>     sys.exit(main(sys.argv[1:]))
>> >>>   File "/usr/local/bin/ansible-playbook", line 249, in main
>> >>>     pb.run()
>> >>>   File
>> >>> "/Library/Python/2.7/site-packages/ansible/playbook/__init__.py",
>> >>> line 339, in run
>> >>>     if not self._run_play(play):
>> >>>   File
>> >>> "/Library/Python/2.7/site-packages/ansible/playbook/__init__.py",
>> >>> line 695, in _run_play
>> >>>     if not self._run_task(play, task, False):
>> >>>   File
>> >>> "/Library/Python/2.7/site-packages/ansible/playbook/__init__.py",
>> >>> line 468, in _run_task
>> >>>     task.ignore_errors =  utils.check_conditional(cond , play.basedir,
>> >>> task.module_vars, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR)
>> >>>   File "/Library/Python/2.7/site-packages/ansible/utils/__init__.py",
>> >>> line 254, in check_conditional
>> >>>     conditional = template.template(basedir, conditional, inject,
>> >>> fail_on_undefined=fail_on_undefined)
>> >>>   File "/Library/Python/2.7/site-packages/ansible/utils/template.py",
>> >>> line 115, in template
>> >>>     varname = template_from_string(basedir, varname, vars,
>> >>> fail_on_undefined)
>> >>>   File "/Library/Python/2.7/site-packages/ansible/utils/template.py",
>> >>> line 357, in template_from_string
>> >>>     res = jinja2.utils.concat(rf)
>> >>>   File "<template>", line 8, in root
>> >>>   File "/Library/Python/2.7/site-packages/jinja2/runtime.py", line
>> >>> 485,
>> >>> in _fail_with_undefined_error
>> >>>     raise self._undefined_exception(hint)
>> >>> jinja2.exceptions.UndefinedError: 'test_err' is undefined
>> >>>
>> >>> ##################
>> >>>
>> >>> When I use a static value, 'yes' it works:
>> >>>
>> >>> - hosts: jump
>> >>>   remote_user: deploy
>> >>>   gather_facts: yes
>> >>>   tasks:
>> >>>     - set_fact: test_err=yes
>> >>>     - debug: var=test_err
>> >>>       ignore_errors: yes
>> >>>
>> >>> output was:
>> >>>
>> >>> ###########
>> >>> PLAY [jump]
>> >>> *******************************************************************
>> >>>
>> >>> GATHERING FACTS
>> >>> ***************************************************************
>> >>> ok: [qa10-jump1]
>> >>>
>> >>> TASK: [set_fact test_err=yes]
>> >>> *************************************************
>> >>> ok: [qa10-jump1]
>> >>>
>> >>> TASK: [debug var=test_err]
>> >>> ****************************************************
>> >>> ok: [qa10-jump1] => {
>> >>>     "test_err": "yes"
>> >>> }
>> >>>
>> >>> PLAY RECAP
>> >>> ********************************************************************
>> >>> qa10-jump1                 : ok=3    changed=0    unreachable=0
>> >>> failed=0
>> >>> ######
>> >>>
>> >>> Isn't this a bug?
>> >>>
>> >>> I am using ansible 1.7.1 release
>> >>>
>> >>> Thanks,
>> >>> Yasir.
>> >
>> > --
>> > 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 [email protected].
>> > To post to this group, send email to [email protected].
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/ansible-project/92b3dfa2-5ad9-414e-be28-e1496ac97a60%40googlegroups.com.
>> > 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d880976b-3ff7-4437-975f-4ce27f0fbbfe%40googlegroups.com.
>
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CANCK7KdHL2UBn1T9d3teyAx9s-k2u1XyLTubTnZh%3D66SNs448w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to