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
    path: '{{ projects_volume }}\{{ item.proj_name }}'
  state: directory
    - { 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

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
  - name: ansible create multiple directory
      path: "{{ item }}"
      state: directory
      - '/d:/abc'
      - '/d:/def'
      - '/d:/ghi'

 - name: Sync the contents of one directory to another, including subdirectories
     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,140 points
+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,140 points
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
+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