标签:detail bin port master my.cnf cto eth0 10.2.1 http
1.文件架构
[root@master template]# tree . ├── jinj2_test.yml ├── meta ├── tasks ├── templates │ └── test3.j2 └── vars
2. test3.j2的内容
[root@master template]# cat templates/test3.j2 {% if PORT %} bind_address={{ansible_eth0.ipv4.address}}:{{ PORT }} {% else %} bind_address={{ansible_eth0.ipv4.address}}:3306 {% endif %} my_ip is: {{ansible_eth0.ipv4.address}}
3. jinj2_test.yml的内容
[root@master template]# cat jinj2_test.yml --- - hosts: test user: root gather_facts: true vars: PORT: 3136 tasks: - name: copy file to client template: src=/roles/template/templates/test3.j2 dest=/root/my.cnf
4.运行的结果
[root@master template]# ansible test -a ‘cat /root/my.cnf‘ 10.2.1.51 | CHANGED | rc=0 >> bind_address=10.2.1.51:3136 my_ip is: 10.2.1.51 10.2.1.230 | CHANGED | rc=0 >> bind_address=10.2.1.230:3136 my_ip is: 10.2.1.230
参考:https://blog.csdn.net/qqhappy8/article/details/79217380
https://blog.51cto.com/linuxg/1788574
标签:detail bin port master my.cnf cto eth0 10.2.1 http
原文地址:https://www.cnblogs.com/hixiaowei/p/10789596.html