Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables Ansible-运行定义为变量的任务_Variables_Ansible_Include_Task_Defined - Fatal编程技术网

Variables Ansible-运行定义为变量的任务

Variables Ansible-运行定义为变量的任务,variables,ansible,include,task,defined,Variables,Ansible,Include,Task,Defined,我想运行一个在变量中定义的任务,如: PlayFile.yml - hosts: all vars: myvar_tasks: - debug: msg: test tasks: - when: myvar_tasks is defined include_tasks: "{{ item }}" loop: "{{ myvar_tasks }}" 我知道这是

我想运行一个在变量中定义的任务,如:

PlayFile.yml

- hosts:  all
  vars:
    myvar_tasks:
      - debug:
          msg: test

  tasks:
    - when: myvar_tasks is defined
      include_tasks: "{{ item }}"
      loop: "{{ myvar_tasks }}"
      
我知道这是行不通的,因为include_任务需要一个文件名/路径作为输入

但有什么办法可以做到这一点吗

可能是
“{{lookup('file','/etc/foo.txt')}}”的一种反向方式


谢谢

包含任务有什么问题?你到底想实现什么,而不是用它来实现?从我看到的情况来看,只有在定义了任务列表时,您才尝试运行任务列表(而不是“任务”),这看起来是
包含任务的完美用例。