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

前端 未结 7 1854
醉酒成梦
醉酒成梦 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:48

    If you want to have your vars in files under group_vars, just move them here. Vars can be in the inventory ([group:vars] section) but also (and foremost) in files under group_vars or hosts_vars.

    For instance, with your example above, you can move your vars for group tests in the file group_vars/tests :

    Inventory file :

    [lb]
    10.112.84.122
    
    [tomcat]
    10.112.84.124
    
    [jboss5]
    10.112.84.122
    
    ...
    
    [tests:children]
    lb
    tomcat
    jboss5
    
    [default:children]
    tests
    

    group_vars/tests file :

    data_base_user=NETWIN-4.3
    data_base_password=NETWIN
    data_base_encrypted_password=
    data_base_host=10.112.69.48
    data_base_port=1521
    data_base_service=ssdenwdb
    data_base_url=jdbc:oracle:thin:@10.112.69.48:1521/ssdenwdb
    

提交回复
热议问题