AWSLearn how to create a sipXcom-based AMI

This is Part 2 of the blog series that will teach you how to deploy sipXcom in AWS DevOps style. In Part 1 of the blog series we learn how to provision a minimal CentOS machine with Ansible-AWS. We launched a CentOS prepared EC2 instance that we will now use to create our own sipXcom AMI. So let’s get started:

Step 1. Connect to AWS console and gather needed facts for Ansible.

Under Services – EC2 – Running Instance – menu we will see something like:

centOS picture

Click on your newly created instance and collect “instance_id” and “public_ip”:


In our demo: instance_id = i-8b3a21b5 and public_ip =

Step 2. Configure Ansible to use gathered information from the above step



I like to keep ansible.cfg and inventory.ini in the current path.

ls -l
                -rw-rw-r-- 1 mihai mihai   55 Aug 23 11:31 ansible.cfg
                 drwxrwxr-x 2 mihai mihai 4096 Sep  2 13:02 files
                -rw-rw-r-- 1 mihai mihai   51 Aug 24 08:54 inventory.ini
                -rw-rw-r-- 1 mihai mihai  725 Sep  2 12:49 provision.yml
                -rw-rw-r-- 1 mihai mihai  811 Sep  2 12:44 sipxcom_template.yml

cat ansible.cfg
                hostfile = inventory.ini
                remote_user = root

We next need to add an AWS group to our inventory.ini where we will define the public_ip of the newly created CentOS template

cat inventory.ini

Note the need of private key to connect to AWS instance. We have generated this key in Part 1 under AWS console — key pair — devops-key.

Next we will add instance_id in the files/info.yml

cd files
cat info.yml
                standard_ami: ami-edb9069e
                sipxcom_ami: ami-e3f1d694
                tiny_instance: t1.micro
                free_instance: t2.micro
                large_instance: m4.large
                ssh_keyname: devops-key
                Inst_id: i-8b3a21b5
                secgroup_id: sg-9a-**********

Step 3. Make a new Ansible playbook to create sipXcom template

First let’s download sipxcom.repo that we will use to install sipXcom

                wget && mv sipxecs*sipxcom.repo
ls -l
               -rw-rw-r-- 1 mihai mihai 101 Aug 30 20:45 awscreds.yml
               -rw-rw-r-- 1 mihai mihai 209 Sep 2 13:11 info.yml
               -rw-rw-r-- 1 mihai mihai 161 Mar 21 09:24 sipxcom.repo

cd ..


Now we will create an ansible playbook called sipxcom_template.yml with the following content:

         cat sipxcom_template.yml
                 - hosts: aws                    # connect to the aws hosts defined in inventory.ini as root
                   remote_user: root
                   gather_facts: yes
                   connection: ssh
                      - name: Copy sipxcom.repo in /etc/yum.repos.d  
                        copy: src=files/sipxcom.repo dest=/etc/yum.repos.d/sipxcom.repo
                      - name: Installing sipxcom. Go get a coffee. It will take a while 
                        yum:  name=sipxcom state=present    # install sipXcom repo after we’ve copy it 

                 - hosts: localhost                    #execute locally AWS api commands section to create sipxcom AMI
                   connection: local
                   remote_user: devops
                   gather_facts: no
                 - files/awscreds.yml
                 - files/info.yml
                   - name: Basic provisioning of sipXcom AMI
	                   ec2_ami:                           # Note we are using ec2_ami module            
  	                   aws_access_key: "{{ aws_id }}"
  	                   aws_secret_key: "{{ aws_key }}"
  	                   region: "{{ aws_region }}"
  	                   instance_id: "{{ inst_id }}"
  	                   wait: no
  	                   name: sipXcom_AMI
    	                   Name: sipXcom_16.02
    	                   Service: sipXcom_UC_server
	                   register: instance
                 - name: Print the results
	           debug: var=instance

Step 4. Execute ansible-playbook command and visualize the newly created sipXcom template


ansible-playbook sipxcom_template.yml

PLAY [aws] *********************************************************************

TASK [setup] *******************************************************************
ok: []

TASK [Copy sipxcom.repo in /etc/yum.repos.d] ***********************************
changed: []

TASK [Installing sipxcom. Go get a coffee. It will take a while] ********************************************************
changed: []

PLAY [localhost] ***************************************************************

TASK [Basic provisioning of sipXcom AMI] ***************************************
changed: [localhost]

TASK [Print the results] *******************************************************
ok: [localhost] => {
“instance”: {
“architecture”: “x86_64”,
“block_device_mapping”: {
“/dev/sda1”: {
“delete_on_termination”: false,
“encrypted”: false,
“size”: 8,
“snapshot_id”: “snap-dc188531”,
“volume_type”: “standard”
“changed”: true,
“creationDate”: “2016-09-02T10:52:49.000Z”,
“description”: null,
“hypervisor”: “xen”,
“image_id”: “ami-a8681adb”,
“is_public”: false,
“location”: “541233277246/sipXcom_AMI”,
“msg”: “AMI creation operation complete”,
“ownerId”: “541233277246”,
“root_device_name”: “/dev/sda1”,
“root_device_type”: “ebs”,
“state”: “available”,
“tags”: {},
“virtualization_type”: “hvm”

PLAY RECAP ********************************************************************* : ok=3 changed=2 unreachable=0 failed=0
localhost : ok=2 changed=1 unreachable=0 failed=0

Now let’s see our new shiny sipXcom based AMI.

Connect to AWS console and under AMI sub-menu:

You should have an entry like this:

Stay tuned for Part 3 where we will create an EC2 instance from sipXcom template and configure newly launched server

In case you missed it, in Part 1 of the blog series we learn how to provision a minimal CentOS machine with Ansible-AWS.