Linux   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ansible 与 Jinja2的结合大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

1.文件架构 [[email protected] template]# tree . ├── jinj2_test.yml ├── meta ├── tasks ├── templates │   └── test3.j2 └── vars 2. test3.j2的内容 [[email protected] template]# cat templates/test3.j2 {

1.文件架构

[[email protected] template]# tree
.
├── jinj2_test.yml
├── Meta
├── tasks
├── templates
│   └── test3.j2
└── vars

2. test3.j2的内容

[[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的内容

[[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.运行的结果

[[email protected] 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

大佬总结

以上是大佬教程为你收集整理的ansible 与 Jinja2的结合全部内容,希望文章能够帮你解决ansible 与 Jinja2的结合所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:ansible结合