Ansible: how to construct a variable from another variable and then fetch it's value

前端 未结 10 484
我寻月下人不归
我寻月下人不归 2020-12-02 22:50

Here is my problem I need to use one variable \'target_host\' and then append \'_host\' to it\'s value to get another variable name whose value I need. If you look at my pl

10条回答
  •  半阙折子戏
    2020-12-02 22:56

    You can try global array var:

    regions:
      us-east-1:
        endpoint: rds.us-east-1.amazonaws.com
      cn-north-1:
        endpoint: rds.cn-north-1.amazonaws.com.cn
      cn-northwest-1:
        endpoint: rds.cn-northwest-1.amazonaws.com.cn
    

    And use it to get value depending of another:

    region_endpoint: "{{ regions[region].endpoint}}"
    

    In your case:

    target_host:
      imap:
        host: imap.max.com
      smtp:
        host: smtp.max.com
    

    then:

    region_endpoint: "{{ target_host[service].host}}"
    

提交回复
热议问题