Ansible使用介绍

72课时
1.9K学过
8分

课程评价 (0)

请对课程作出评价:
0/300

学员评价

暂无精选评价
2分钟

14 示例2:template,for,引用字典

vim for2.conf.j2

{% for port in ports %}

server{

​ listen {{ port.listen_port }}

}

{% endfor %}

cp testfor.yml testfor2.yml

vim testfor2.yml

– hosts: websrvs

remote_user: root

vars:

ports:

– listen_port: 81

– listen_port: 82

– listen_port: 83

tasks:

– name: copy conf

template:src=for2.conf.j2 dest/data/for2.conf

执行结果:每台主机生成for2.conf文件,内容如下