Ansible - read inventory hosts and variables to group_vars/all file

前端 未结 7 1796
醉酒成梦
醉酒成梦 2020-12-23 11:47

I have a dummy doubt that keeps me stuck for a long time. I have a very banal inventory file with hosts and variables:

[lb]
10.112.84.122

[tomcat]
10.112.84         


        
7条回答
  •  醉梦人生
    2020-12-23 12:34

    Considering your previous example:

    inventory file:

    [db]
    10.112.83.37
    

    group_vars/all

    data_base_url=jdbc:oracle:thin:@{{ db }}:1521/ssdenwdb
    

    template file:

    oracle_url = {{ data_base_url }}
    

    You might want to replace your group_vars/all with

    data_base_url="jdbc:oracle:thin:@{{ groups['db'][0] }}:1521/ssdenwdb"
    

提交回复
热议问题