What is the proper way to read an option in INI-file on remote node with Ansible?

前端 未结 1 1453
花落未央
花落未央 2021-01-13 01:14

I am writing an Ansible role that installs and updates some specific enterprise software. I would like to compare the installed version (if it is installed) to the one I am

相关标签:
1条回答
  • 2021-01-13 02:10

    Seems like a use case for facts.d.

    1. Write a shell or Python script that inspects those ini files and dumps required fields as JSON object to stdout.

    2. Place this script into /etc/ansible/facts.d/custom_soft.fact and make it executable.

    3. Then you can use these facts as follows:

      - shell: install_custom_soft.sh
        when: ansible_local.custom_soft.component_ver | int > 4
      

    If your ini files are very simple, you may do the job even without script, just make a link like this:

    ln -s /etc/custom_soft/config.ini /etc/ansible/facts.d/custom_soft.fact
    

    and all config.ini keys will be available to Ansible via ansible_local.custom_soft variable.

    P.S. Despite the name "local facts" this should be done on remote machine.

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