Ansible Dynamically copy files directories depending on hostname

0 votes

To share the labour of copying and processing lists of repositories on remote systems, I want to dynamically assign IPs to folders.

Goal is to have the following:

app/_data/repo-list-0 copies to 10.0.0.1
app/_data/repo-list-1 copies to 10.0.0.2
app/_data/repo-list-2 copies to 10.0.0.3

etc..
# ansible/hosts
10.0.0.1
10.0.0.2
10.0.0.3

etc..

my source structure is like so where each directory contains ~10 json files

app/_data/repo-list-0/repo-list-[1-10].json
app/_data/repo-list-1/repo-list-[2-20].json
app/_data/repo-list-2/repo-list-[3-30].json

etc..

Copy Data Task

# ansible/playbooks/copy_data.yml
---
  - name: Copy Data
    hosts: all
    user: ec2-user
    vars:
      app: ...
    tasks:
     - name: copy repo-range to hosts
       copy:
         src: "app/_data/repo-list-0"
         dest: "{{ ansible_env.HOME }}/{{ app }}/_data"
       when: inventory_hostname == "10.0.0.1"
     - name: copy repo-range to hosts
       copy:
         src: "app/_data/repo-list-1"
         dest: "{{ ansible_env.HOME }}/{{ app }}/_data"
       when: inventory_hostname == "10.0.0.2"
     - name: copy repo-range to hosts
       copy:
         src: "app/_data/repo-list-2"
         dest: "{{ ansible_env.HOME }}/{{ app }}/_data"
       when: inventory_hostname == "10.0.0.3"

etc..

When the entire application is launched, new instances are deployed in AWS, and I have to manually modify each IP address. This is why I dynamically transfer the data.

When the host changed, I attempted to make a global variable and increment the source.

Dec 14, 2022 in AWS by Tejashwini
• 3,820 points
504 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In AWS

0 votes
1 answer

How can i copy tables from one database to other on AWS?

You can use AWS Data pipeline to ...READ MORE

answered Jul 5, 2018 in AWS by Priyaj
• 58,020 points
4,788 views
0 votes
1 answer

AWS S3 CLI : error while trying to copy files locally using terminal

For the first error you should add ...READ MORE

answered Aug 3, 2018 in AWS by Archana
• 4,170 points
11,411 views
0 votes
1 answer

Why is subscriber optional on ansible sns?

Hey @bug_seeker, I could not find any ...READ MORE

answered Aug 8, 2018 in AWS by Priyaj
• 58,020 points

edited Jun 8, 2020 by Sirajul 956 views
0 votes
1 answer

How to copy a folder from S3 to Elastic Beanstalk instance on its creation?

I had encountered similar problem. But i ...READ MORE

answered Aug 24, 2018 in AWS by Archana
• 4,170 points
4,572 views
0 votes
1 answer

Boto3 - python script to view all directories and files

There are no folders, only S3 object ...READ MORE

answered Sep 14, 2018 in AWS by Priyaj
• 58,020 points
41,448 views
0 votes
1 answer

Boto3 - python script to view all directories and files

There are no folders, only S3 object ...READ MORE

answered Sep 17, 2018 in AWS by Priyaj
• 58,020 points
3,132 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,020 points
1,676 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,020 points
854 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,020 points
2,353 views
0 votes
1 answer

Python division

You're using Python 2.x, where integer divisions ...READ MORE

answered Oct 13, 2018 in Python by SDeb
• 13,300 points
765 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