【问题标题】:ansible - include the static script file in rolesansible - 在角色中包含静态脚本文件
【发布时间】:2017-02-08 19:56:29
【问题描述】:

下面是我的名为 webserver 的 ansibel 角色的目录结构

本地主机角色#树

.
├── readme.md
├── site.yml
└── webserver
    ├── files
    │   ├── createswap.sh
    │   └── nginxkeyadd.sh
    ├── handlers
    │   └── main.yml
    ├── tasks
    │   └── main.yml
    ├── templates
    │   ├── helloworld.conf.j2
    │   └── index.html.j2
    └── vars
        └── main.yml

我的任务/main.yml 看起来像

- name: Create swap file 50MB
  script: /etc/ansible/roles/webserver/files/createswap.sh
- name: add GPG key for nginx
  script: /etc/ansible/roles/webserver/files/nginxkeyadd.sh 
- name: Install nginx on target
  apt: name={{ item }} state=latest
  with_items:
   - rsync
   - git
   - nginx

在 task/main.yml 中指定本地脚本文件的绝对路径,如

script: /etc/ansible/roles/webserver/files/nginxkeyadd.shscript: /etc/ansible/roles/webserver/files/createswap.sh 。脚本没有任何 ansible 变量。 这是 ansible 的好习惯吗?

【问题讨论】:

    标签: ansible ansible-2.x


    【解决方案1】:

    在 ansible 中是好的做法吗?

    没有。摘自docs

    任何副本、脚本、模板或包含任务(在角色中)都可以引用角色/x/{files,templates,tasks}/(目录取决于任务)中的文件,而无需相对或绝对路径

    使用 shell 脚本代替原生 Ansible 模块也是一种反模式。

    【讨论】:

      猜你喜欢
      • 2014-12-20
      • 2021-04-05
      • 2014-12-31
      • 1970-01-01
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多