我们有许多 csv 文件,并包含各种配置的查找数据。
#eg of lookup file csv
hostname,ip,country,type,port
atlanta1,1.2.3.4,US,ui,8080
toronto1,1.2.3.5,CA,ui,8080
toronto2,1.2.3.9,CA,db,8000
another3,1.2.3.6,UK,db,8000
我们需要填充复杂且串联的变量,然后需要在其他剧本中使用这些变量,
# Eg. concatenated variables http:{{hostname}}:{{port}} from above lookup csv file
ui_cluster = http://atlanta1:8080;http://toronto1:8080
db_cluster = http://atlanta1:8000;http://toronto1:8000
..最后在最终的剧本中使用连接的变量
#configurations in final customer template
my_build_script_UIcluster= {{ui_cluster}}
my_build_script_DBcluster= {{db_cluster}}
我想使用从上面的查找中创建的变量以在模板中使用。如何做到这一点或最好的方法?
最佳答案
include_csv
模块 https://github.com/mkouhei/ansible-role-includecsv听起来像您要找的东西。
关于Ansible:如何从查找文件创建变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47096152/