pka*_*mol -1 ansible ansible-2.x
我正在使用以下site.yml剧本,并通过
ansible-playbook site.yml
- hosts: some_hosts
vars:
pip_install_packages:
- name: docker
- tasks:
- name: Conditionally include bar vars
include_vars:
file: bar_vars.yml
when: some_condition == "bar"
- name: Conditionally include foo vars
include_vars:
file: foo_vars.yml
when: some_condition == "foo"
roles:
- role1
- role2
environment:
SOME_ENV_VAR: "{{ vault_some_env_var }}"
Run Code Online (Sandbox Code Playgroud)
呼叫失败,如下所示:
错误!字段“主机”为必填项,但未设置
但显而易见的是上述情况,hosts现场已被设置!
有什么建议么?
您可以在剧本中混合任务和角色,还可以使用“ pre_tasks”和“ post_tasks”控制何时执行任务。
在我看来,您有-不应该执行的任务-可能认为这是一种新玩法。
- hosts: some_hosts
vars:
pip_install_packages:
- name: docker
- tasks: <-- This should not have a dash
Run Code Online (Sandbox Code Playgroud)
使用前任务和后任务控制与角色相关的任务执行时间的示例:
---
- hosts: all
name: Roles with pre and post tasks
vars:
somevar: foobar
roles:
- { role: common, tags: ["common"] }
pre_tasks:
- debug:
msg: I execute before roles
post_tasks:
- debug:
msg: I execute after roles
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1454 次 |
| 最近记录: |