Target multiple hosts with different configurations

0 votes

I have checked some similar questions but those questions don't answer mine.

I have three hosts:

  • host_abc_01
  • host_def_01
  • host_ghi_01

I want to create directories this way:

  • host_abc_01:

    • d:\abc\dir1\dir2
  • host_def_01:

    • d:\def\dir1\dir2
  • host_ghi_01:

    • d:\ghi\dir1\dir2

the only different is the directory name. the sub directories have the same name.

Instead of creating three different roles with own tasks and varfiles, is there any way to achieve this in one play?

- name: create project directory
  win_file:
    path: '{{ projects_volume }}\{{ item.proj_name }}'
  state: directory
  loop:
    - { proj_name: 'abc', when: "'abc' in inventory_hostname" }
    - { proj_name: 'def', when: "'def' in inventory_hostname" }
    - { proj_name: 'ghi', when: "'ghi' in inventory_hostname" }

But all directories are created on all hosts.

Any help would be appreciated.

Jun 28 in AWS by Omar
• 140 points
32 views

1 answer to this question.

0 votes

You do not need three different roles to create three directories. You can use with_items module to create three different directories:

- hosts: all
  tasks:
  - name: ansible create multiple directory
    file:
      path: "{{ item }}"
      state: directory
    with_items:
      - '/d:/abc'
      - '/d:/def'
      - '/d:/ghi'

 - name: Sync the contents of one directory to another, including subdirectories
   win_robocopy:
     src: d:\abc\dir1
     dest: C:\def\dir1
     recurse: yes
answered Jul 3 by Lavanya

edited Jul 3

Related Questions In AWS

0 votes
1 answer

How to switch between multiple accounts with AWS SDK

You can define multiple profiles in ~/.aws/credentials ...READ MORE

answered Aug 24, 2018 in AWS by Priyaj
• 56,520 points
49 views
+2 votes
1 answer

How to combine multiple S3 objects in the target S3 object w/o leaving S3

"However sometimes our raw objects are not ...READ MORE

answered Aug 28, 2018 in AWS by Priyaj
• 56,520 points
1,713 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
145 views
0 votes
1 answer
0 votes
1 answer

Different availability zones for network load balancer

Yes, you can use multiple availability zones ...READ MORE

answered May 14 in AWS by Renold
41 views