Do not use shell when you have native modules 

ansible can create whole trees using the file module 

example: 

---
- hosts: localhost

  tasks:
    - name: create dir structure
      file:
        path: 'ibm/{{ item }}'
        state: directory
      with_items:
        - it
        - logisitic

this simple playbook will create the directoires ibm/it and ibm/logistics 
even if the parent folder ibm does not exist . 



you can streamline this with loop control to create to loops one with the 
company names other with the subdirectories 

https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html

On Monday, May 18, 2020 at 1:39:22 PM UTC-5, דודו דודו wrote:
>
> Hi, I’m trying to create folder structure on HDFS storage. I have 3 main 
> folders and each has subfolders.
>
>
> Thank you.
>
>  
>
> *Configuration file:*
>
>
>
> companies:
>      - company_folder_name: /ibm
>        department:
>             - it
>             - logistic
>      - company_folder_name: /hp
>        department:
>      - company_folder_name: /dell
>        department:
>             - it
>
>  
>
>  
>
> *Playbook: *
>
>
> ## Createing the main folders - working fine ##
>    - name: create company folders
>      shell: hadoop fs -mkdir {{ item.company_folder_name }}
>      register: result
>      ignore_errors: yes
>      with_items:
>             - "{{ companies }}"
>
> ## Create subfolders - Not working ##
>    - name: create department folders
>      shell: hadoop fs -mkdir {{ item.company_folder_name 
> }}/{{item.department}}
>      register: result
>      ignore_errors: yes
>      with_items:
>             - "{{ companies }}"
>
>
On Monday, May 18, 2020 at 1:39:22 PM UTC-5, דודו דודו wrote:
>
> Hi, I’m trying to create folder structure on HDFS storage. I have 3 main 
> folders and each has subfolders.
>
>
> Thank you.
>
>  
>
> *Configuration file:*
>
>
>
> companies:
>      - company_folder_name: /ibm
>        department:
>             - it
>             - logistic
>      - company_folder_name: /hp
>        department:
>      - company_folder_name: /dell
>        department:
>             - it
>
>  
>
>  
>
> *Playbook: *
>
>
> ## Createing the main folders - working fine ##
>    - name: create company folders
>      shell: hadoop fs -mkdir {{ item.company_folder_name }}
>      register: result
>      ignore_errors: yes
>      with_items:
>             - "{{ companies }}"
>
> ## Create subfolders - Not working ##
>    - name: create department folders
>      shell: hadoop fs -mkdir {{ item.company_folder_name 
> }}/{{item.department}}
>      register: result
>      ignore_errors: yes
>      with_items:
>             - "{{ companies }}"
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/23c7d3cd-b38f-475f-8740-0104d6db088f%40googlegroups.com.

Reply via email to