jeudi 15 octobre 2015

How to create basic EC2 instance with Ansible

I am trying to learn the Ansible with all my AWS stuff. So the first task which I want to do is creation the basic EC2 instance with all settings which I need and install docker there. I wrote the Playbook according to Ansible docs, but it doesn't really work. My Playbook:

# The play operates on the local (Ansible control) machine.
- name: Create a basic EC2 instance v.1.1.0 2015-10-14
  hosts: localhost
  connection: local
  gather_facts: false

# Vars.
  vars:
      hostname: Test_By_Ansible
      keypair: MyKey
      instance_type: t2.micro
      security_group: my security group   
      image: ami-d05e75b8                 # Ubuntu Server 14.04 LTS (HVM)
      region: us-east-1                   # US East (N. Virginia)
      vpc_subnet_id: subnet-b387e763      
      sudo: True
      locale: ru_RU.UTF-8

# Launch instance. Register the output.
  tasks:
    - name: Launch instance
      ec2:
         key_name: "{{ keypair }}"
         group: "{{ security_group }}"
         instance_type: "{{ instance_type }}"
         image: "{{ image }}"
         region: "{{ region }}"
         vpc_subnet_id: "{{ vpc_subnet_id }}"
         assign_public_ip: yes
         wait: true
         wait_timeout: 500
         count: 1                         # number of instances to launch
         instance_tags:
            Name: "{{ hostname }}"
            os: Ubuntu
            type: WebService
      register: ec2

    # Create and attach a volumes.
    - name: Create and attach a volumes
      ec2_vol:
         instance: "{{ item.id }}"
         name: my_existing_volume_Name_tag
         volume_size: 1   # in GB
         volume_type: gp2
         device_name: /dev/sdf
         with_items: ec2.instances
      register: ec2_vol

    # Configure mount points.
    - name: Configure mount points - mount device by name
      mount: name=/system src=/dev/sda1 fstype=ext4 opts='defaults nofail 0 2' state=present
      mount: name=/data src=/dev/xvdf fstype=ext4 opts='defaults nofail 0 2' state=present
      #wait_timeout: 500

    # Do some stuff on instance.
    # locale

But this Playbook crushes on volumes mount. And I don't know how to set locale because - locale_gen: name=de_CH.UTF-8 state=present line doesn't help. Could somebody get me a helping hand, please?




1 commentaire: