ansible自动创建远程两个目录,且在两个目录中创建对应的文件。

回复 收藏

[root@Herry ansible]# cat create_doublefile.yml 

---

- name: create_file to client

  hosts: 192.168.224.131

  user: root

  #vars_files: 

  # - /etc/ansible/varfile.yml

  gather_facts: false

  tasks:

    - name: create_directory

      file: path=/tmp/{{ item.directory }} state=directory owner=root group=root mode=0755 

    - name: create_doublefile

      file: path=/tmp/{{ item.directory }}/{{ item.file }} state=touch owner=root group=root mode=0755

      with_items: 

       - { 'directory': [ "pythonstudy3", "pythonstudy3/999" ] }

       - { 'file': [ 1.txt,2.txt,3.txt ] }

报错如下:

TASK [create_directory] ***********************************************************************************************************************************************

fatal: [192.168.224.131]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to have been in '/etc/ansible/create_doublefile.yml': line 9, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  tasks:\n    - name: create_directory\n      ^ here\n"}

        to retry, use: --limit @/etc/ansible/create_doublefile.retry

为什么不行?

2018-05-27 21:51 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: