gpt4 book ai didi

Ansible:禁止混合角色和任务?

转载 作者:行者123 更新时间:2023-12-03 01:39:49 28 4
gpt4 key购买 nike

我正在使用以下 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 }}"

调用失败如下:

ERROR! the field 'hosts' is required but was not set

但如上所示,hosts 字段已设置!

有什么建议吗?

最佳答案

您可以在剧本中混合任务和角色,还可以使用“pre_tasks”和“post_tasks”控制任务的执行时间。

在我看来,你有一个不应该存在的任务,可能认为这是一个新游戏。

- hosts: some_hosts
vars:
pip_install_packages:
- name: docker

- tasks: <-- This should not have a dash

使用前置任务和后置任务来控制与角色相关的任务执行时间的示例:

---
- 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

关于Ansible:禁止混合角色和任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49881489/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com