ansible的底层是用Python写的,所使用的模块是 paramiko 和一些常用的执行模块 比如:yum ,created等
playbooks 剧本怎么写?
----------------------------------------------------------------------模板------------------------------------------------------------
- host: webservers(组名)
remote_user: root (用户名)
vars: (模板模块调用)- packages: tree (模板名称具体名称 tree )
task: (具体内容) - name: yum install tree (备注工作内容与在Linux环境中一致)
yum: name=tree state=lastest (具体执行的名称name=tree(名称) state=lastest(最新版))
(注:对所执行的名称 状况进行描述) - name: yum install tree (备注工作内容与在Linux环境中一致)
yum: name={{ packages }} state=lastest
(安装名称调用模块{{ packages }} 状态=最新版 ) - name: create user (创建用户)
user: name=user1 (用户名称user1) - name: create many user (创建用户)
user: name={{ item }} state=absent (创建用户模板item 状态=absent)
with_items: (模板)- user1 (用户1)
- user2 (用户2)
- user3 (用户3)
- name: cp httpd.conf
template: src=/root/templates/httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf
(template: src=拷贝的地址 dest=拷贝的目的地址)
notify:(触发器)- restart httpd(执行完上一步命令后触发执行本次命令)
handlers: (触发执行模板)
- restart httpd(执行完上一步命令后触发执行本次命令)
- name: restart httpd (名称 启动httpd 服务)
service: name=httpd state=restarted
(服务类型:name=httpd state=重启服务)
- packages: tree (模板名称具体名称 tree )