ignore_errors does not take variable

498 views
Skip to first unread message

Yasir Saleem

unread,
Oct 6, 2014, 1:22:18 PM10/6/14
to ansible...@googlegroups.com
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.

Mark

unread,
Oct 7, 2014, 10:10:11 AM10/7/14
to ansible...@googlegroups.com
Hi Yasir,


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

Yasir Saleem

unread,
Oct 7, 2014, 10:51:48 AM10/7/14
to ansible...@googlegroups.com
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.

Michael Peters

unread,
Oct 7, 2014, 10:57:16 AM10/7/14
to ansible...@googlegroups.com
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
> --
> 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-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> 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.

Yasir Saleem

unread,
Oct 7, 2014, 12:58:46 PM10/7/14
to ansible...@googlegroups.com
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
######

shirou

unread,
Feb 26, 2015, 10:21:49 AM2/26/15
to ansible...@googlegroups.com
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
> https://groups.google.com/d/msgid/ansible-project/d880976b-3ff7-4437-975f-4ce27f0fbbfe%40googlegroups.com.

Tom Bamford

unread,
Feb 28, 2015, 10:55:49 PM2/28/15
to ansible...@googlegroups.com

On 26 February 2015 at 17:21, shirou <shiro...@gmail.com> wrote:

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?

The last time I needed to have conditional ignore_errors, because that option did not accept a variable I had to duplicate the task in question. One version of the task had ignore_errors: yes and had a conditional when: my_var | bool and the other had no such setting and the conditional when: not my_var | bool.

Something like this:

vars:
  myvar: yes
tasks:
  - some_module: name=blah state=present
    ignore_errors: yes
    when: myvar | bool
  - some_module: name=blah state=present
    when: not myvar | bool

Hope this helps

Tom

Reply all
Reply to author
Forward
0 new messages