1.文件架构
@H_419_8@[[email protected] template]# tree.├── jinj2_test.yml├── Meta├── tasks├── templates│ └── test3.j2└── vars
2. test3.j2的内容
@H_419_8@[[email protected] 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的内容
@H_419_8@[[email protected] 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.运行的结果
@H_419_8@[[email protected] template]# ansible test -a ‘cat /root/my.cnf‘10.2.1.51 | CHANGED | rc=0 >>bind_address=10.2.1.51:3136my_ip is: 10.2.1.5110.2.1.230 | CHANGED | rc=0 >>bind_address=10.2.1.230:3136my_ip is: 10.2.1.230
参考:https://blog.csdn.net/qqhappy8/article/details/79217380
https://blog.51cto.com/linuxg/1788574
总结以上是内存溢出为你收集整理的ansible 与 Jinja2的结合全部内容,希望文章能够帮你解决ansible 与 Jinja2的结合所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)