Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide skipped tasks output in Ansible

I have Ansible role, for example

---
- name: Deploy app1
  include: deploy-app1.yml
  when: 'deploy_project == "{{app1}}"'

- name: Deploy app2
  include: deploy-app2.yml
  when: 'deploy_project == "{{app2}}"'

But I deploy only one app in one role call. When I deploy several apps, I call role several times. But every time there is a lot of skipped tasks output (from tasks which do not pass condition), which I do not want to see. How can I avoid it?

like image 764
32cupo Avatar asked Aug 28 '16 08:08

32cupo


People also ask

How do you not show Ansible when skipping?

I'm assuming you don't want to see the skipped tasks in the output while running Ansible. Set this to false in the ansible. cfg file.

How do I skip tasks in Ansible?

If you assign the never tag to a task or play, Ansible will skip that task or play unless you specifically request it ( --tags never ).

How do you run or skip only certain tasks in playbook?

The easiest way to run only one task in Ansible Playbook is using the tags statement parameter of the “ansible-playbook” command. The default behavior is to execute all the tags in your Playbook with --tags all .

How do you handle long running tasks in Ansible?

By default, for Ansible tasks, the connections stay open until the task is done on each node, but this may not be the desired behavior for some functions as sometimes the task can take more time than SSH timeouts. You can run such long running tasks in the background and check their status later.


3 Answers

I'm assuming you don't want to see the skipped tasks in the output while running Ansible.

Set this to false in the ansible.cfg file.

display_skipped_hosts = false

Note. It will still output the name of the task although it will not display "skipped" anymore.

UPDATE: by the way you need to make sure ansible.cfg is in the current working directory.

Taken from the ansible.cfg file.

ansible will read ANSIBLE_CONFIG, ansible.cfg in the current working directory, .ansible.cfg in the home directory or /etc/ansible/ansible.cfg, whichever it finds first.

So ensure you are setting display_skipped_hosts = false in the right ansible.cfg file.

Let me know how you go

like image 64
Omar E Avatar answered Oct 18 '22 00:10

Omar E


Since ansible 2.4, a callback plugin name full_skip was added to suppress the skipping of task names and skipping keyword in the ansible output. You can try the below ansible configuration:

[defaults]
stdout_callback = full_skip
like image 16
Leon Xie Avatar answered Oct 17 '22 22:10

Leon Xie


Ansible allows you to control its output by using custom callbacks.

In this case you can simply use the skippy callback which will not output anything on a skipped task.

That said, skippy is now deprecated and will be removed in ansible v2.11.

like image 14
ydaetskcoR Avatar answered Oct 18 '22 00:10

ydaetskcoR