How can I hide skipped tasks output in Ansible

后端 未结 5 2153
你的背包
你的背包 2020-12-30 23:32

I have Ansible role, for example

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

- name: Deploy app2
  include         


        
相关标签:
5条回答
  • 2020-12-30 23:42

    If you are using roles, you can use when to cancel the include in main.yml

    # roles/myrole/tasks/main.yml
    - include: somefile.yml
      when: somevar is defined
    
    
    # roles/myrole/tasks/somefile.yml
    - name: this task will only run (and be seen in the output) if somevar is defined
      debug:
        msg: "Hello World"
    
    0 讨论(0)
  • 2020-12-30 23:54

    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
    
    0 讨论(0)
  • 2020-12-30 23:56

    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

    0 讨论(0)
  • 2020-12-31 00:02

    If you don't mind losing colours you can elide the skipped tasks by piping the output through sed:

    ansible-playbook whatever.yml | sed -nr '/^TASK/{h;n;/^skipping:/{n;b};H;x};p'
    
    0 讨论(0)
  • 2020-12-31 00:04

    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.

    0 讨论(0)
提交回复
热议问题