In part 4 of the AWS Ansible sipXcom blog series I’ll show you how to add AWS Route 53 entries to match a newly created server.

At the end of part 3 we have already created and start running a production ready sipXcom server on AWS EC2 instance.

The only shortcoming was the need to use the server’s IP addresses, but those IPs change as soon as you shut down an instance and who want’s to remember numbers.

In this (short) tutorial we will use Ansible’s route53 module documented here:

Step 1. Connect to route 53 service

Go to  AWS management console → Services → Route 52

AWS management console


Get your hosted zone name. In our case this is

Hosted zones

Step 2.  Rewrite info.yml to use new hosted zone

cat files/info_hosted.yml

         standard_ami: ami-edb9069e
         sipxcom_ami: ami-b49defc7
         tiny_instance: t1.micro
         free_instance: t2.micro
         large_instance: m4.large
         ssh_keyname: devops-key
         inst_id: i-8b3a21b5
         secgroup_id: sg-9a9ca7fd
         net_host: uc1

Note: domain.

Step 3. Create new playbook for configuring EC2 instance


$ cat configure_sipxcom_named.yml
         - hosts: localhost
           connection: local
           remote_user: devops
           gather_facts: no
           - files/awscreds.yml
           - files/info_hosted.yml
           - name: Basic provisioning of EC2 instance
  	           aws_access_key: "{{ aws_id }}"
  	           aws_secret_key: "{{ aws_key }}"
  	           region: "{{ aws_region }}"
  	           image: "{{ sipxcom_ami }}"
  	           instance_type: "{{ free_instance }}"
  	           key_name: "{{ ssh_keyname }}"
  	           count: 1
  	           state: present
  	           group_id: "{{ secgroup_id }}"
  	           wait: yes
  	           vpc_subnet_id: subnet-29a32841
  	           assign_public_ip: yes
	           register: ec2info
            - name: Print the results
	            debug: var=ec2info
            - name: Add all instance public IPs to host group
	            add_host: hostname={{ ec2info.instances[0].public_ip  }}

We talked about the following section in previous blog articles:

  - name: Add Route 53 entries for newly created EC2 Instance
  	command: create
  	record: "{{ net_host }}.{{ net_domain }}"
  	type: A
  	ttl: 7200
  	value: "{{ ec2info.instances[0].public_ip  }}"
  	overwrite: yes

For today’s tutorial we will look just at this section:
command: create -self explanatory

zone: – my hosted zone

record: “{{ net_host }}.{{ net_domain }}” – We want to create an A record that will point to my above
(info_hosted.yml) explained FQDN

value: “{{ ec2info.instances[0].public_ip }}” – A record will point to the dynamically changing IP address
obtained in ec2info json object

overwrite: yes – Mandatory since our IP will change frequently

          - name: Add TCP SIP  SRV
  	          command: create
  	          overwrite: yes
  	          record: "_sip._tcp.{{ net_domain }}."
  	          type: SRV
  	          value: "10 10 5060 {{ net_host }}.{{ net_domain }}"
          - name: Add UDP SIP  SRV
  	          command: create
                  overwrite: yes
  	          record: "_sip._udp.{{ net_domain }}."
  	          type: SRV
  	          value: "10 10 5060 {{ net_host }}.{{ net_domain }}"

With record: “_sip._tcp.{{ net_domain }}.” – we are creating DNS SRV’s with TCP and UDP that will have them pointing to “10 10 5060 {{ net_host }}.{{ net_domain }}”

Note: If you want to read more about DNS SRV’s check this link:

We talked about this section in previous blog articles as well:

       - hosts: ec2hosts
  	      - files/awscreds.yml
  	      - files/info_hosted.yml
        - name: Configure sipxcom
	        remote_user: root
	        shell: sipxecs-setup --noui --sip_domain "{{ sip_domain }}" --sip_realm "{{ sip_realm }}" --net_domain "{{ net_domain }}" 
        --net_host "{{ net_host }}"

Step 4. Run playbook and connect to Web GUI using FQDN

ansible-playbook configure_sipxcom_named.yml
PLAY [localhost] ***************************************************************

TASK [Basic provisioning of EC2 instance] **************************************
changed: [localhost]

TASK [Print the results] *******************************************************
ok: [localhost] => {
	"ec2info": {
    	"changed": true,
    	"instance_ids": [
    	"instances": [
            	"ami_launch_index": "0",
            	"architecture": "x86_64",
            	"block_device_mapping": {
                	"/dev/sda1": {
                    	"delete_on_termination": false,
                    	"status": "attached",
                    	"volume_id": "vol-482ac9ca"
            	"dns_name": "",
            	"ebs_optimized": false,
            	"groups": {
                	"sg-9a9ca7fd": "devops"
            	"hypervisor": "xen",
            	"id": "i-03ef0b32",
            	"image_id": "ami-b49defc7",
            	"instance_type": "t2.micro",
            	"kernel": null,
            	"key_name": "devops-key",
            	"launch_time": "2016-09-05T13:00:39.000Z",
            	"placement": "eu-west-1c",
            	"private_dns_name": "",
            	"private_ip": "",
            	"public_dns_name": "",
            	"public_ip": "",
            	"ramdisk": null,
            	"region": "eu-west-1",
            	"root_device_name": "/dev/sda1",
            	"root_device_type": "ebs",
            	"state": "running",
            	"state_code": 16,
            	"tags": {
                	"Name": ""
            	"tenancy": "default",
            	"virtualization_type": "hvm"
    	"tagged_instances": []

TASK [Add all instance public IPs to host group] *******************************
changed: [localhost]

TASK [Wait for SSH to come up] *************************************************
ok: [localhost]

TASK [Add Route 53 entries for newly created EC2 Instance] *********************
changed: [localhost]

PLAY [ec2hosts] ****************************************************************

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

TASK [Configure sipxcom] *******************************************************
changed: []

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

Under AWS console — Route 53 you should see entries like:

AWS console entries


Now you can access your Web UI by name: Web UI by name

You could also dig for services with:

dig -t SRV
         ; <<>> DiG 9.10.3-P4-RedHat-9.10.3-9.P4.fc22 <<>> -t SRV
         ;; global options: +cmd
         ;; Got answer:
         ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60750
         ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
         ; EDNS: version: 0, flags:; udp: 4096
         ;    IN    SRV
         ;; ANSWER SECTION: 3600    IN    SRV    10 10 5060
         ;; Query time: 45 msec
         ;; SERVER:
         ;; WHEN: Wed Sep 07 10:57:36 EEST 2016
         ;; MSG SIZE  rcvd: 91

Don’t miss next tutorial where we will populate our new EC2 instance in DevOps style.

To see the previous blogs in this AWS Ansible sipXcom Blog Series click below:

Part 1: Learn how to Provision a minimal CentOS machine with Ansible-AWS, used to create our own sipXcom based AMI

Part 2: Learn how to create a sipXcom-based AMI

Part 3: Create an EC2 instance from sipXcom template and configure newly launched server