playbook核心元素之 --> 模板template 介绍
templates:文件文件,内部嵌套有模板语言脚本(使用模板语言编写)
[root@ansible ~]# ansible-doc -l | grep "^\<template\>" --> template是一个模块 template Templates a file out to a remote server.
[root@node1 ~]# ansible-doc -s template --> 查看 template模块的参数 src= dest= mode= onwer= group= ...
注意:此模拟不能再命令行使用,而只能用于playbook
实际使用范例
[root@ansible ~]# vim test4.yaml - hosts: centos7 remote_user: root tasks: - name: install httpd yum: name=httpd state=latest - name: copy config file template: src=/root/httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf notify: restart httpd service - name: start httpd service service: name=httpd state=started handlers: - name: restart httpd service service: name=httpd state=restarted
转载于:https://blog.51cto.com/sixijie123/1878076