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 29, 2019 in AWS by Omar
• 140 points
650 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 4, 2019 by Lavanya

edited Jul 4, 2019

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
• 58,020 points
2,181 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
• 58,020 points
12,941 views
0 votes
1 answer
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,024 views
+2 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 15, 2019 in AWS by Renold
1,670 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP