实际上,我需要这样的东西:
- hosts: localhost
tasks:
- name: Perforce template
import_tasks: ./../vsphere-client/perforce/template_to_vm.yml
when: new_server_type == "perforce"
- name: Gitlab Pgbouncer template
import_tasks: ./../vsphere-client/gitlab-pgbouncer/template_to_vm.yml
when: new_server_type == "gitlab-pgbouncer"
- name: Gitlab Postgres template
import_tasks: ./../vsphere-client/gitlab-postgres/template_to_vm.yml
when: new_server_type == "gitlab-postgres"
- name: Build API template
import_tasks: ./../vsphere-client/build-api/template_to_vm.yml
when: new_server_type == "build-api"但是它会给出一个错误,比如:
ERROR! unexpected parameter type in action: <type 'bool'>我知道这是不受支持的,但有没有办法做到这一点?
发布于 2020-07-09 04:15:51
一定有其他东西你没有显示,因为你的代码看起来没问题,应该可以工作。我怀疑问题出在您正在导入的文件中。
同时,如果切换到include_tasks没有问题,您可以通过一项任务大大缩短上述时间:
---
- hosts: localhost
tasks:
- name: "{{ new_server_type }} template"
include_tasks: "./../vsphere-client/{{ new_server_type }}/template_to_vm.yml"如果您确实需要检查以确保new_server_type具有正确的值,仍然可以这样做。
---
- hosts: localhost
vars:
allowed_types:
- perforce
- gitlab-pgbouncer
- gitlab-postgres
- build-api
tasks:
- name: "{{ new_server_type }} template"
include_tasks: "./../vsphere-client/{{ new_server_type }}/template_to_vm.yml"
when: new_server_type in allowed_types发布于 2020-07-09 04:16:32
你有没有试过使用include_tasks ie。类似于下面的内容
- include_tasks: setup-RedHat.yml
when: ansible_os_family == 'RedHat'因此,对于您来说,它将如下所示
- hosts: localhost
tasks:
- name: Perforce template
include_tasks: ./../vsphere-client/perforce/template_to_vm.yml
when: new_server_type == "perforce"发布于 2021-12-14 12:49:11
正如前面两个答案都已经暗示的那样,陷阱是import_tasks与include_tasks。documentation for import_tasks说:
大多数关键字,包括循环和条件,只适用于导入的任务,而不适用于此语句本身。如果您需要应用其中任何一个,请改用ansible.builtin.include_tasks。
https://stackoverflow.com/questions/62800665
复制相似问题