cancel
Showing results for 
Search instead for 
Did you mean: 
AndrewC666
Flight Engineer
Flight Engineer
  • 632 Views

Where can I read about for example "failed_when" in an exam?

Jump to solution

I'm thinking of taking ex 294 in the near future.

I'm picturing myself having a brain fart and needing to use the man pages but as far as I can see there is no man page for things like "failed_when" or is there? 

If I want to know more about a module or look for examples I can do ansible-doc somemodule but for things like "failed_when" is there a resource availble in the exam that might be helpful ?

Thanks

Labels (1)
Tags (1)
1 Solution

Accepted Solutions
ric
Flight Engineer Flight Engineer
Flight Engineer
  • 578 Views

Hi, @AndrewC666 

I can't talk about the RHCE Exam (EX294) but, in the Red Hat Course Lab environment of the RH294 course, I see that you can at least do two things in the shell of the "workstation" machine:

1 - Get the description of the failed_when keyword:

[student@workstation ~]$ ansible-doc -t keyword failed_when
failed_when:
applies_to:
- Task
description: Conditional expression that overrides the task's normal 'failed' status.
priority: 0
template: implicit
type: list

 

2 - Run some "creative" commands, such as the following, to see the examples available in the YAML files in the /usr/share/ansible directory tree:

[student@workstation ~]$ find /usr/share/ansible/ -name '*.yml' -exec grep --with-filename --line-number --before 5 --after 5 'failed_when' {} + | less
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-191- --original {{ __ha_cluster_tempfile_original_cib_xml.path }}
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-192- --new {{ __ha_cluster_tempfile_cib_xml.path }}
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-193- register: __ha_cluster_cib_diff
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-194- check_mode: no
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-195- changed_when: not ansible_check_mode
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml:196: failed_when:
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-197- - __ha_cluster_cib_diff.rc != 0 # success, CIBs are the same
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-198- - __ha_cluster_cib_diff.rc != 1 # success, CIBs are not the same
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-199-
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-200-- name: Write CIB diff to its tempfile
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-201- copy:
--
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-7- block:
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-8- - name: Enable service 'high-availability' in firewalld
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-9- command: firewall-cmd --add-service high-availability
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-10- when: ansible_facts.services['firewalld.service'].state == 'running'
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-11- register: __ha_cluster_firewall_cmd
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml:12: failed_when:
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-13- - __ha_cluster_firewall_cmd.rc != 0
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-14- - __ha_cluster_firewall_cmd.rc != 11 # already enabled
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-15-
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-16- - name: Enable service 'high-availability' in firewalld permanent config
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-17- command: firewall-cmd --permanent --add-service high-availability
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-18- register: __ha_cluster_firewall_cmd
...


I hope this helps! Good luck on your RHCE / EX294 Exam!

View solution in original post

7 Replies
Puffin
Cadet
Cadet
  • 592 Views

I haven't taken the exam yet so I can't say this is 100% accurate. But I read that an offline versin of docs.ansible.com is available durin the exam if you open the web browser. 

If that's true, then you'd be able to pull up https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html to read up on it 

ric
Flight Engineer Flight Engineer
Flight Engineer
  • 579 Views

Hi, @AndrewC666 

I can't talk about the RHCE Exam (EX294) but, in the Red Hat Course Lab environment of the RH294 course, I see that you can at least do two things in the shell of the "workstation" machine:

1 - Get the description of the failed_when keyword:

[student@workstation ~]$ ansible-doc -t keyword failed_when
failed_when:
applies_to:
- Task
description: Conditional expression that overrides the task's normal 'failed' status.
priority: 0
template: implicit
type: list

 

2 - Run some "creative" commands, such as the following, to see the examples available in the YAML files in the /usr/share/ansible directory tree:

[student@workstation ~]$ find /usr/share/ansible/ -name '*.yml' -exec grep --with-filename --line-number --before 5 --after 5 'failed_when' {} + | less
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-191- --original {{ __ha_cluster_tempfile_original_cib_xml.path }}
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-192- --new {{ __ha_cluster_tempfile_cib_xml.path }}
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-193- register: __ha_cluster_cib_diff
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-194- check_mode: no
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-195- changed_when: not ansible_check_mode
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml:196: failed_when:
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-197- - __ha_cluster_cib_diff.rc != 0 # success, CIBs are the same
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-198- - __ha_cluster_cib_diff.rc != 1 # success, CIBs are not the same
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-199-
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-200-- name: Write CIB diff to its tempfile
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/create-and-push-cib.yml-201- copy:
--
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-7- block:
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-8- - name: Enable service 'high-availability' in firewalld
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-9- command: firewall-cmd --add-service high-availability
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-10- when: ansible_facts.services['firewalld.service'].state == 'running'
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-11- register: __ha_cluster_firewall_cmd
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml:12: failed_when:
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-13- - __ha_cluster_firewall_cmd.rc != 0
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-14- - __ha_cluster_firewall_cmd.rc != 11 # already enabled
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-15-
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-16- - name: Enable service 'high-availability' in firewalld permanent config
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-17- command: firewall-cmd --permanent --add-service high-availability
/usr/share/ansible/collections/ansible_collections/redhat/rhel_system_roles/roles/ha_cluster/tasks/firewall.yml-18- register: __ha_cluster_firewall_cmd
...


I hope this helps! Good luck on your RHCE / EX294 Exam!

Chetan_Tiwary_
Community Manager
Community Manager
  • 537 Views

Thanks @ric , I think this is super helpful!

AndrewC666
Flight Engineer
Flight Engineer
  • 490 Views

Thanks all. Where do I confirm @Puffin hunch ? 

Chetan_Tiwary_
Community Manager
Community Manager
  • 434 Views

@AndrewC666 try raising a support request with exam suppor here : https://rhtapps.redhat.com/comments

to confirm the same. I think they can help you on the same.

0 Kudos
Cyrille_V
Mission Specialist
Mission Specialist
  • 447 Views

Hi!

I think failed_when is used mainly as a condition for action in Ansible playbooks, for example

....

register: nginx_status
failed_when: "'inactive' in nginx_status.stdout"

 

Chetan_Tiwary_
Community Manager
Community Manager
  • 433 Views

@Cyrille_V spot on ! Ansible lets you define what “failure” means in each task using the failed_when conditional:

 

      command: df -h /var
      register: disk_usage
      changed_when: false
      failed_when: "'/dev/sda1' in disk_usage.stdout and '80%' in disk_usage.stdout"

 

 

Join the discussion
You must log in to join this conversation.