大佬教程收集整理的这篇文章主要介绍了文件中的 ansible 查找;基于 2 个变量分隔,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Ansible 在文件中查找分号;基于 2 的分隔和查找 变量
#输入csv文件:
@H_450_9@Sysport;name;address;column1;port;column2;column3 host001$port0;host001;x.x.x.10;x.x.x.10:port0,x.x.x.11:port0;port0;port0;envq1 host001$port1;host001;x.x.x.10;x.x.x.10:port1,x.x.x.11:port1;port1;port1;envq1 host001$port2;host001;x.x.x.10;x.x.x.10:port2,x.x.x.11:port2;port2;port2;envq1 host001$port3;host001;x.x.x.10;x.x.x.10:port3,x.x.x.11:port3;port3;port3;envq1 host001$port4;host001;x.x.x.10;x.x.x.10:port4,x.x.x.11:port4;port4;port4;envq1 host001$port5;host001;x.x.x.10;x.x.x.10:port5,x.x.x.11:port5;port5;port5;envq1
代码
@H_450_9@--- - name: lookup example # Include host,group of hosts hosts: [dummy] # Count of servers to run in batch serial: 10 # Collect basic information from servers gather_facts: True #ignore_unreachable: true # Execution tasks tasks: - sHell: ls /directory register: port - deBUG: msg: "{{ lookup('csvfile',inventory_hostname ~ '$' ~ item file=/ansible/files/repos.csv delimiter=; col=3 }}" with_items: "{{ port.stdout_lines }}"
错误:
@H_450_9@TASK [deBUG] ******************************************************************* fatal: [dummy1]: Failed! => {"Failed": true,"msg": "ERROR! template error while templaTing String: expected token ',',got
'文件'"}
预期:结果
消息中“server_repo”的值
如 the fine manual 所示,@H_450_9@csvfile 查找希望将第二个参数作为字符串,而不是自由形式的标记集合(更不用说示例中缺少的右括号):
@H_450_9@- debug: msg: "{{ lookup('csvfile',inventory_hostname ~ '$' ~ item ~ ' file=/ansible/files/vips.csv delimiter=; col=3') }}" with_items: "{{ port.stdout_lines }}"
您也可以自行决定将该 csv 关键部分提取到 @H_450_9@var,因为每次迭代都会评估 @H_450_9@vars: 块:
@H_450_9@- debug: msg: "{{ lookup('csvfile',my_csv_key ~ ' file=/ansible/files/vips.csv delimiter=; col=3') }}" vars: my_csv_key: "{{ inventory_hostname ~ '$' ~ item }}" with_items: "{{ port.stdout_lines }}"
两者的工作方式相同,但对于人们来说,第二个可能更容易理解
以上是大佬教程为你收集整理的文件中的 ansible 查找;基于 2 个变量分隔全部内容,希望文章能够帮你解决文件中的 ansible 查找;基于 2 个变量分隔所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。