role综合测试
1、模拟安装httpd
[ ansible]# tree roles/ roles/ ├── app │ ├── files │ │ └── vhosts.conf │ ├── handlers │ │ └── main.yml │ ├── tasks │ │ ├── copyfile.yml │ │ ├── group.yml │ │ ├── main.yml │ │ ├── start.yml │ │ ├── templ.yml │ │ ├── user.yml │ │ └── yum.yml │ ├── templates │ │ └── httpd.conf.j2 │ └── vars │ └── main.yml
tree目录层级
[ tasks]# cat main.yml - include: group.yml - include: user.yml - include: yum.yml - include: templ.yml - include: copyfile.yml - include: start.yml [ tasks]# cat group.yml - name: create group group: name=app [ tasks]# cat user.yml - name: create user user: name=app group=app [ tasks]# cat yum.yml - name: install package yum: name=httpd [ tasks]# cat templ.yml - name: copy conf template: src=httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf notify: restart service [ tasks]# cat copyfile.yml - name: copy cofig copy: src=vhosts.conf dest=/etc/httpd/conf.d/ owner=app [ tasks]# cat start.yml - name: start service service: name=httpd state=started enabled=yes
tasks
#这里碰到一个坑,如果把main.yml 给成其他名字报错如下 ERROR! The requested handler ‘restart service‘ was not found in either the main handlers list nor in the listening handlers list #抗我了2个小时尴尬 [ app]# cat handlers/main.yml - name: restart service service: name=httpd state=restarted
handlers/main.yml
[ ansible]# cat roles/app/vars/main.yml username: app groupname: app
[ ansible]# cat app_role.yml - hosts: date remote_user: root roles: - app
templates、files为测试目录自己改吧改吧,测试成功哈哈
相关推荐
Greatemperor 2020-05-03
逆时针 2020-02-10
taiyangshenniao 2019-12-16
lihaoxiang 2019-11-14
89463661 2019-11-01
guchengxinfen 2019-07-18
benbendy 2016-09-30
LiteHeaven 2019-07-01
freesky 2019-07-01
wlzjiayou 2019-06-30
chenhua 2019-06-28
Martnn 2019-06-27
ououlal 2010-12-20
83251242 2019-06-20
dxbjfu0 2019-06-20
哈嘿Blog 2018-01-12
sunnyishere 2012-04-20
Python探路者 2019-04-22