Ansible使用介绍

72课时
1.9K学过
8分

课程评价 (0)

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

学员评价

暂无精选评价
2分钟

13 示例1:template,for

vim for1.conf.j2

{% for port in ports %}

server{

​ listen {{ port }}

}

{% endfor %}

vim testfor.yml

– hosts: websrvs

remote_user: root

vars:

ports:

– 81

– 82

– 83

tasks:

– name: copy conf

​ template: src=for1.conf.j2 dest=/data/for1.conf

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