<p>This is why configuration management software exists.
Example for Ansible and AWS:</p>

<pre><code>- name: Create a sandbox instance
  hosts: localhost
  gather_facts: False
  vars:
    timezones_path: /some/path/timezones.list
    key_name: my_keypair
    instance_type: m1.small
    security_group: my_securitygroup
    vpc_subnet: my_vpc_id
    image: my_ami_id
    region: us-east-1
  tasks:
    - name: Load timezones list
      shell: "echo {{ item }}"
      with_lines: "cat {{ timezones_path|quote }}"
      register: timezones

    - name: Launch instances
      ec2:
         key_name: "{{ keypair }}"
         group: "{{ security_group }}"
         instance_type: "{{ instance_type }}"
         image: "{{ image }}"
         wait: true
         region: "{{ region }}"
         vpc_subnet_id: "{{ vpc_subnet }}"
         assign_public_ip: yes
         count: "{{ timezones|length }}"
      register: ec2

    - name: Add new instance to host group
      add_host:
        hostname: "{{ item.1.public_ip }}"
        timezone: "{{ item.0 }}"
        groupname: launched
      with_together:
        "{{ timezones }}"
        "{{ ec2.instances }}"

    -name: Tag instances with timezones
      ec2_tag:
        region: "{{ region }}"
        resource: "{{ item.id }}"
        tags:
          Timezone: "{{ item.timezone }}"
      with_items: "{{ groups['launched'] }}"

    - name: Wait for SSH to come up
      wait_for:
        host: "{{ item.public_dns_name }}"
        port: 22
        delay: 60
        timeout: 320
        state: started
      with_items: "{{ ec2.instances }}"

- name: Configure instance(s)
  hosts: launched
  become: True
  gather_facts: True
  tasks:
    - name: Run deploy script
      shell: "/path/to/script.sh --tz {{timezone}}"
</code></pre>

<p>Path to script in last line should be for host which runs Ansible, not remote.</p>

CC BY-SA 3.0
2017-06-16T00:29:21.763Z
Thanks! Ansible is the next buzzword I will be reading up on.
cylondude
CC BY-SA 3.0
2017-06-16T00:08:51.573Z
2017-06-16T00:08:51.573Z
chupasaurus
<p>Sorry for the general and vague nature of my question.  Let me describe with some more detail what I would like to do (or what I think I would like to do).  </p>

<p>I have a shell script for ubuntu 16.04 that sets up my instance how I want it.  But it needs to use two different variable inputs for each different instance.  For example, if across all the instances that I wanted to set up, I wanted to put in different timezone, I could start with a list of all the timezones, and iteratively deploy a machine for each timezone.  Maybe the solution I look for would drop a textfile with the timezone I wanted on each instance. That would be enough for me to read the file and set it up.  I just need a solution that will allow me to create any number of cloud instances of ubuntu 16.04 and deliver seperate textfiles with these timezones.  They are all identical except the file with the timezone. </p>

<p>I'd like to be able to create all these instances simultaneously from the command line or through some R package for an API interface. Digital Ocean, AWS, or even some local option if I should be considering that. </p>

<p>Is this a job for docker or vagrant?  What is the tool for this kind of deployment? Maybe a script to loop through creating instances with these? </p>

<docker><vagrant>
Deploying a set of cloud instances based on a list of parameter differences
cylondude
# Deploying a set of cloud instances based on a list of parameter differences

(Asked by: username_0 on 2017-06-15)

Sorry for the general and vague nature of my question. Let me describe with some more detail what I would like to do (or what I think I would like to do).

I have a shell script for ubuntu 16.04 that sets up my instance how I want it. But it needs to use two different variable inputs for each different instance. For example, if across all the instances that I wanted to set up, I wanted to put in different timezone, I could start with a list of all the timezones, and iteratively deploy a machine for each timezone. Maybe the solution I look for would drop a textfile with the timezone I wanted on each instance. That would be enough for me to read the file and set it up. I just need a solution that will allow me to create any number of cloud instances of ubuntu 16.04 and deliver seperate textfiles with these timezones. They are all identical except the file with the timezone.

I'd like to be able to create all these instances simultaneously from the command line or through some R package for an API interface. Digital Ocean, AWS, or even some local option if I should be considering that.

Is this a job for docker or vagrant? What is the tool for this kind of deployment? Maybe a script to loop through creating instances with these?

**Tags:** docker, vagrant


---

## 1 answers

### Answer by username_1 on 2017-06-16. Score: 1 | Accepted answer

This is why configuration management software exists.
Example for Ansible and AWS:
- name: Create a sandbox instance
  hosts: localhost
  gather_facts: False
  vars:
    timezones_path: /some/path/timezones.list
    key_name: my_keypair
    instance_type: m1.small
    security_group: my_securitygroup
    vpc_subnet: my_vpc_id
    image: my_ami_id
    region: us-east-1
  tasks:
    - name: Load timezones list
      shell: "echo {{ item }}"
      with_lines: "cat {{ timezones_path|quote }}"
      register: timezones

    - name: Launch instances
      ec2:
         key_name: "{{ keypair }}"
         group: "{{ security_group }}"
         instance_type: "{{ instance_type }}"
         image: "{{ image }}"
         wait: true
         region: "{{ region }}"
         vpc_subnet_id: "{{ vpc_subnet }}"
         assign_public_ip: yes
         count: "{{ timezones|length }}"
      register: ec2

    - name: Add new instance to host group
      add_host:
        hostname: "{{ item.1.public_ip }}"
        timezone: "{{ item.0 }}"
        groupname: launched
      with_together:
        "{{ timezones }}"
        "{{ ec2.instances }}"

    -name: Tag instances with timezones
      ec2_tag:
        region: "{{ region }}"
        resource: "{{ item.id }}"
        tags:
          Timezone: "{{ item.timezone }}"
      with_items: "{{ groups['launched'] }}"

    - name: Wait for SSH to come up
      wait_for:
        host: "{{ item.public_dns_name }}"
        port: 22
        delay: 60
        timeout: 320
        state: started
      with_items: "{{ ec2.instances }}"

- name: Configure instance(s)
  hosts: launched
  become: True
  gather_facts: True
  tasks:
    - name: Run deploy script
      shell: "/path/to/script.sh --tz {{timezone}}"

Path to script in last line should be for host which runs Ansible, not remote.

> **Comments:**
> **username_0**: Thanks! Ansible is the next buzzword I will be reading up on.  

---

