create multiple directories using ansible

前端 未结 1 1951
一向
一向 2021-01-19 02:04

I want to create multiple directories(test1,test2) with 2 sub directories (/home/test1/bin and /home/test2/conf) similarly for test2. My playbook looks like this :



        
相关标签:
1条回答
  • 2021-01-19 03:00

    I think that errors raised because you used file module 2 times in 1 task. You should only use 1 module per task.

    In your case, you should use nested loop to create multiple directories and subdirectories.

    Example:

    ---
    - hosts: localhost
      tasks:
        - name: test
          file: path=/tmp/{{item.0}}/{{item.1}} state=directory
          with_nested:
            - ['test1', 'test2']
            - ['bin', 'conf']
    
    0 讨论(0)
提交回复
热议问题