1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| --- - hosts: webservers # 对 webservers组中所有机器执行 vars: # 添加变量 hello: Ansible remote_user: root # 以什么用户来执行 tasks: # 多个task通过 name名字区分 - name: Add repo #### 第一:拉取代码 yum_repository: name: nginx description: nginx repo baseurl: http://nginx.org/packages/centos/7/$basearch/ gpgcheck: no enabled: 1 tags: addrepo - name: Install nginx #### 第二:安装nginx yum: name: nginx state: latest tags: install - name: Copy nginx configuration file #### 第三:配置nginx copy: src: ./site.conf dest: /etc/nginx/conf.d/site.conf - name: Start nginx #### 第四:启动nginx service: name: nginx state: started tags: startngx - name: Create wwwroot directory #### 第五:创建网站根目录 file: dest: /var/www/html state: directory - name: Create test page index.html #### 第六:创建“主页” shell: echo "hello {{hello}}" > /var/www/html/index.html # 在这里可以引用变量
|