The goal of this topic is to present one of the solutions to deploy self-configured instances on the 3DS OUTSCALE Cloud.

This solution is a proper alternative to tools like Ansible or Salt, since you do not need to add inbound rules in the security groups of your instance. However, do not forget to open outbound flows if you are in a VPC, and create routes and an Internet gateway.

Step 1: Create an instance image executing user data

  1. Create a script that is executed only when necessary:

    To prevent from any further execution, we will end the execution by creating a file, which existence will be checked before re-executing itself.

     

    1. To create the script, run the following command:

      $> vim /opt/bootscript.sh
    2. Insert the following content for the script in the text editor:

      #!/usr/bin/bash
      if [ ! -f /var/setup_vm ]; then
          curl 169.254.169.254/latest/user-data | bash
      fi
  2. Ensure that this script will be executed as a service using the following command:

    1. To create the boot setup script, run the following command:

      $> vim /usr/lib/systemd/system/setup_boot.service
    2. Insert the following content for the script in the text editor:

      [Unit]
      Description=Execute user-datas to setup the machine
      After=network-online.target
      [Service]
      Type=oneshot
      RemainAfterExit=no
      ExecStart=/usr/bin/bash /opt/bootscript.sh
      [Install]
      WantedBy=multi-user.target
  3. Enable the service using the following command:

    command
    $> systemctl enable setup_boot.service
  4. Stop the instance and create an OMI from it. For more information, see Creating an OMI from an Instance.



Step 2: Create an instance for a small python webserver

  1. With Boto2, create an instance using the previously created OMI:

    from boto.ec2.regioninfo import EC2RegionInfo
    from boto.vpc import VPCConnection
     
    your_ak, your_sk = "XXXXXAAAXXXXXX", "ZZZZZZBBBBBBZZZZZZBBBBBBBZZZZZZZ"
    outscale_endpoint = EC2RegionInfo(endpoint="fcu.eu-west-2.outscale.com")    # you can change the region
    outscale_fcu = VPCConnection( aws_access_key_id = your_ak, aws_secret_access_key = your_sk, region = outscale_endpoint)
    
    userdatas = '''
    	#!/usr/bin/bash
    	yum install python supervisor -y
    	wget http://public.osu.eu-west-2.outscale.com/package.tar.gz
    	tar -xvf package.tar.gz
    	mv package/* /root/
    	pip install -r /root/requirements.txt
    	mv /root/supervisord.conf /etc/supervisord.conf
    	systemctl start supervisord
    	touch /var/setup_vm
    	'''
    resa = outscale_fcu.run_instances(image_id=<you_new_omi>, key_name=keypair, instance_type='t2.medium', userdata=userdatas)
    print resa.instances[0].ip_address

    You can now connect to your instance and enjoy your brand-new webserver.



Windows® is a registered trademark of Microsoft Corporation in the United States and/or other countries.

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.

See Legal Mentions.