jinja2模板
调用变量 判断语句 循环语句 toc 调用变量 Jinja2是 Python 下一个被广泛应用的模版引擎, Ansible 可以使用jinja2模板调用变量等。 jinja2 ## 写一个模板文件(使用facts变量) [root@Ansible project]# vim jinja.j2 {{ ansible_distribution }} ## 受控端系统 {{ ansible_eth0.ipv4.address }} ## 受控端eth0的IP {{ ansible_hostname }} ## 受控端主机名 {{ ansible_memtotal_mb // 4 }} ## 受控端总内存除以4取整 ## 模板文件放到受控端(根据变量转换成值) [root@Ansible project]# vim copy_file.yml - hosts: hosts tasks: - name: Copy File template: ##copy模块不支持转换模板文件 src: ./jinja.j2 dest: /tmp/test.txt - name: Cat File shell: cat /tmp/test.txt register: test_file - name: Print test_file debug: var: test_file.stdout_lines ##