怎麼使用 Ansible 的 Template 系統?
14. 怎麼使用 Ansible 的 Template 系統?
舉例說明
$ vi hello_world.txt.j2 Hello "{{ dynamic_word }}" ↑ ↑ ↑$ vi template_demo.yml 1 --- 2 - name: Play the template module 3 hosts: localhost 4 vars: 5 dynamic_word: "World" 6 7 tasks: 8 - name: generation the hello_world.txt file 9 template: 10 src: hello_world.txt.j2 11 dest: /tmp/hello_world.txt 12 13 - name: show file context 14 command: cat /tmp/hello_world.txt 15 register: result 16 17 - name: print stdout 18 debug: 19 msg: "{{ result.stdout_lines }}" 20 21 # vim:ft=ansible :
2016-12-14-ansible-template1.gif $ ansible-playbook template_demo.yml$ ansible-playbook template_demo.yml -e "dynamic_word=ansible"$ ansible-playbook template_demo.yml -e "dynamic_word=Day14"
怎麼讓 Playbooks 切換不同的環境?

2016-12-14-ansible-template2.gif
後語
相關連結
Last updated
