在ansbile中直接执行yml文件

来源:互联网 发布:经典c语言程序小游戏 编辑:程序博客网 时间:2024/06/05 09:16

在我的测试case中,正常执行的命令为:

$ ansible-playbook web-notls.yml -i hosts

如果你将playbook文件权限设置为可执行,并且首行如下所示:

#!/bin/env ansible-playbook

这样,你就可以通过直接调用它自己来执行,如下所示:

$ ./web-notls.yml

类似的,我case的命令就可以这么写了:

$ ./web-notls.yml -i hosts

下面是我用ansible安装nginx写的playbook:

#!/bin/env ansible-playbook- name: Configure webserver with nginx  hosts: webservers  sudo: True  tasks:    - name: Obtain Nginx rpm      yum:        name: http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.12.1-1.el7.ngx.x86_64.rpm    - name: Install Nginx      yum:        name: nginx        state: latest    - name: copy nginx config file      copy:        src: files/nginx.conf        dest: /etc/nginx/sites-available/default    - name: copy index.html      template:        src: templates/index.html.j2        dest: /usr/share/nginx/html/index.html        mode: 0644    - name: restart nginx      service: name=nginx state=restarted