Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Ansible从变量列表创建目录_Ansible_Ubuntu 20.04_Raspberry Pi4 - Fatal编程技术网

Ansible从变量列表创建目录

Ansible从变量列表创建目录,ansible,ubuntu-20.04,raspberry-pi4,Ansible,Ubuntu 20.04,Raspberry Pi4,我开始学习ansible并尝试创建一些目录,这些目录将用于playbook中的不同任务,因此我为每个目录创建变量 到目前为止我的剧本 --- - name: tests hosts: all vars: dir1: /data/dir1 dir2: /mnt/dir2 tasks: - debug: msg: "{{ item }}" loop: - "{{ dir1 }}"

我开始学习ansible并尝试创建一些目录,这些目录将用于playbook中的不同任务,因此我为每个目录创建变量

到目前为止我的剧本

---
- name: tests
  hosts: all
  vars:
    dir1: /data/dir1
    dir2: /mnt/dir2
  tasks:
    - debug:
        msg: "{{ item }}"
      loop:
        - "{{ dir1 }}"
        - "{{ dir2 }}"
    - name: create directories
      file:
        path: "{{ item }}"
        state: directory
        mode: '0755'
        loop:
          - "{{ dir1 }}"
          - "{{ dir2 }}"
调试按预期工作,但我收到此错误

The task includes an option with an undefined variable. The error was: 'item' is undefined
也试过

    - name: create directories
      file:
        path: "{{ item }}"
        state: directory
        mode: '0755'
        with_items:
          - "{{ dir1 }}"
          - "{{ dir2 }}"
在Ubuntu 20.04上使用Ansible 2.9.6,在Raspberry Pi 4上使用LTS

答:循环缩进错误(与_项相同)。修正语法

-名称:创建目录
文件:
路径:“{item}}”
状态:目录
模式:“0755”
循环:
-“{{dir1}}”
-“{{dir2}}”
Ansible可能会在模块参数之前检查变量。这可能是Ansible失败的原因,
'item'未定义
而不是模块文件的
'loop'未知参数