1、初始化一个role

[root@bogon ~]# ansible-galaxy init /etc/ansible/roles/websrvs

查看已经创建的role
[root@bogon ~]# ls /etc/ansible/roles/
webservs 2、配置role 把初始化后 role里面没用的删除,只留下面四个目录 [root@bogon ~]# cd /etc/ansible/roles/webservs/
[root@bogon webservs]# ls
handlers README.md tasks templates vars
[root@bogon webservs]# ls templates/
index.html.j2 nginx.conf.j2 配置变量vars [root@bogon webservs]# cat vars/main.yml
---
# vars file for /etc/ansible/roles/webservs
worker_processes: 4
worker_connections: 768
max_open_files: 65506 tasks 文件内容 [root@bogon webservs]# cat tasks/main.yml
---
# tasks file for /etc/ansible/roles/webservs
- name: install nginx
command: yum install nginx -y - name: copy nginx config file
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify: restart nginx - name: copy index.html
template:
src: index.html.j2
dest: /usr/share/nginx/www/index.html
mode: 0644
notify: restart nginx - name: see file
command: ls /root
notify: restart nginx handlers 文件内容: [root@bogon webservs]# cat handlers/main.yml
---
# handlers file for /etc/ansible/roles/webservs
- name: restart nginx
service: name=nginx state=restarted 模板文化内容: [root@bogon webservs]# cat templates/nginx.conf.j2
worker_processes {{ worker_processes }};
worker_rlimit_nofile {{ max_open_files }}; events {
worker_connections {{ worker_connections }};
} http {
server {
listen 80;
root /usr/share/nginx/www;
index index.html index.htm default.html index.php;
server_name loclhost;
location / {
try_files / =404;
}
} } [root@bogon webservs]# cat templates/index.html.j2
<html>
<head>
<title>welcome to american</title>
</head>
<body>
<h1>nginx, confitured by ansible</h1>
<p>if you can see this, ansible successfully installed nginx.</p> <p>{{ ansible_hostname }}</p>
</body>
</html> 3、配置playbook,把role添加进来 [root@bogon ~]# cat nginx_role.yaml
---
- hosts: webservers
become: yes
become_method: sudo
roles:
- role: webservs 4、开始执行Playbook [root@bogon ~]# ansible-playbook nginx_role.yaml

最新文章

  1. WaterfallFlowLayout瀑布流用重写UICollectionViewFlowLayout类实现
  2. html基础01
  3. Python 基礎 - 字符轉編碼操作
  4. docker--buildbot安装
  5. lua里面求int数组的union,diff,inter,distinct 方法实现
  6. [Android]Volley源码分析(二)
  7. HDU1176
  8. [编]IoT The Internet of Things (IoT) 物联网
  9. apecceosummit2016
  10. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解
  11. 安装sinopia-ldap
  12. 从app里跳到appstore评论页面的实现
  13. Ubuntu 14.10安装SecureCRT 7.3
  14. 因host命令导致无法正常SHUTDOWN的实验
  15. 【Git之旅】2.Git对象
  16. 【Linux基础】Unix与Linux操作系统介绍
  17. UML图之类图(转)
  18. iOS开发 -------- 图片浏览器初步
  19. 【ANT】输入中文格式为乱码
  20. 用到的linux命令

热门文章

  1. Django学习系列11:在服务器中处理POST请求
  2. solr 基础
  3. IT项目开发流程
  4. ThinkPHP 模型方法 setInc() 和 setDec()
  5. JZOJ5373【NOIP2017提高A组模拟9.17】信仰是为了虚无之人
  6. 【SQL-分组合并字符串】把相同分组的某个字段合并为同一个字符串(使用函数)
  7. css中&quot;.&quot;,&quot;,&quot;,“~”和“&gt;”符号的意义
  8. 项目的Servlet类找不到
  9. Centos 由字符界面 init 3 切换图形界面 init 5
  10. &#39;vue&#39; 不是内部或外部命令,也不是可运行的程序 或批处理文件