Ansible stdout Formatting

后端 未结 4 2151
终归单人心
终归单人心 2021-02-14 01:03

Assuming the below tasks:

shell: \"some_script.sh\" register: \"some_script_result\"

debug: msg: \"Output: {{ some_script_result.stdout_li

相关标签:
4条回答
  • 2021-02-14 01:35

    Another option:

    https://blog.alexgittings.com/improving-the-ansible-output-with-anstomlog/

    just store it inside ansible/ansible.cfg

    ➜ tree ansible     
    ansible
    ├── ansible.cfg
    ├── callbacks
    │   ├── anstomlog.py
    └── playbooks
        └── nginx.yaml
    
    
    ANSIBLE_CONFIG=ansible/ansible.cfg ansible-playbook -u centos --private-key .ssh/key -i `terraform output bastion_ip`, ansible/playbooks/nginx.yaml
    

    0 讨论(0)
  • 2021-02-14 01:53

    I was trying do the following changes, still i did not got the output format of yaml or debug options output properly. Later i found the ansible user configuration pick up it from user's config file. So i changed callbacks at user specific location and it worked.

    [automation@ansibleserver ~]$ ansible --version
       ansible 2.9.9
       config file = /home/automation/ansible.cfg
    
    
    # Use the YAML callback plugin.
       stdout_callback = yaml
    # Use the stdout_callback when running ad-hoc commands.
    bin_ansible_callbacks = True
    

    So ensure, even though you changed at /etc/ansible/ansible.conf , try at user's config file too to get the good result. instead of yaml , debug also gives good helpful format ( for linux users)

    0 讨论(0)
  • 2021-02-14 02:00

    Try this option. You’ll love it.

    There's a new YAML callback plugin introduced with Ansible 2.5 — meaning any machine running Ansible 2.5.0 or later can automatically start using this format without installing custom plugins.

    To use it, edit your ansible.cfg file (either global, in /etc/ansible/ansible.cfg, or a local one in your playbook/project), and add the following lines under the [defaults] section:

    # Use the YAML callback plugin.
    stdout_callback = yaml
    # Use the stdout_callback when running ad-hoc commands.
    bin_ansible_callbacks = True
    

    Now I can easily read through your output message

    0 讨论(0)
  • 2021-02-14 02:01

    Here is bug report about an issue:

    https://github.com/ansible/ansible/issues/27078 - why is ansible's default output not more human readable... stilll?

    The possible answers:

    [defaults]
    nocows = True
    # minimal, debug, yaml
    stdout_callback = yaml
    

    or:

    ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook ....
    
    0 讨论(0)
提交回复
热议问题