Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
re-add role otc_dns
Browse files Browse the repository at this point in the history
  • Loading branch information
eumel8 committed Jan 15, 2018
1 parent a12a018 commit 27e1b4b
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 113 deletions.
41 changes: 31 additions & 10 deletions roles/otc_dns/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ otc_dns
============

OTC role for DNS. This role creates zones, zone records and reverse
entries.
entries (PTR records).

Variables:
^^^^^^^^^^
Expand All @@ -20,25 +20,46 @@ Variables:
+-------------------------+---------------------------------------------+
| zone_email | Email address of SOA |
+-------------------------+---------------------------------------------+
| zone_ttl | DNS zonei TTL in sec |
| zone_ttl | DNS zone TTL in sec |
+-------------------------+---------------------------------------------+
| zone_records | List of zone records |
+-------------------------+---------------------------------------------+
| ptr_name | FQDN for PTR record |
+-------------------------+---------------------------------------------+


Functions:
^^^^^^^^^^

Create::
create::

ansible-playbook tenant_yml.yml -e "zone_name=ansible.otc.telekomcloud99.com" -e "localaction=create"

ansible-playbook tenant_ini.yml -e "zone_name=ansible.internal.corp" -e "vpc_name=ansible-vpc01" -e "localaction=create"


ptrcreate::

ansible-playbook tenant_yml.yml -e "zone_name=ansible.otc.telekomcloud99.com" -e "ecs_name=ansible-test01" -e "localaction=ptr_create"


show::

ansible-playbook tenant_yml.yml -e "zone_name=ansible.otc.telekomcloud99.com" -e "localaction=show"

ansible-playbook tenant_ini.yml -e "zone_name=ansible.internal.corp" -e "vpc_name=ansible-vpc01" -e "localaction=show"


list::

++
ansible-playbook tenant_yml.yml -e "zone_name=ansible.otc.telekomcloud99.com" -e "localaction=list"

Show::
ansible-playbook tenant_ini.yml -e "zone_name=ansible.internal.corp" -e "vpc_name=ansible-vpc01" -e "localaction=list"

++

List::
delete::

++
ansible-playbook tenant_yml.yml -e "zone_name=ansible.otc.telekomcloud99.com" -e "localaction=delete"

Delete::
ansible-playbook tenant_ini.yml -e "zone_name=ansible.internal.corp" -e "vpc_name=ansible-vpc01" -e "localaction=delete"

++
40 changes: 13 additions & 27 deletions roles/otc_dns/tasks/create.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
- name: Lookup zone_id
include: lookup.yml

- name: Delete current zone
include: delete.yml
when: zone_id is defined

- name: Send request to API (create zone)
uri:
url: "{{ AUTH_URL_DNS }}/v2/zones"
Expand All @@ -17,30 +24,9 @@
- debug:
msg: "{{ zone }}"

#- name: Send request to API (create security group)
# vars:
# secgroup_name: "{{ item }}"
# uri:
# url: "{{ AUTH_URL_VPC }}/v1/{{ PROJECT_ID }}/security-groups"
# method: POST
# body_format: raw
# follow_redirects: all
# return_content: yes
# validate_certs: yes
# headers:
# Content-Type: "application/json"
# X-Auth-Token: "{{ token['x_subject_token'] }}"
# body: "{{ lookup('template', 'create.json.j2')|to_json }}"
# when: secgroups is defined
# register: secgroupcreate
# with_items:
# - "{{ secgroups }}"
# loop_control:
# loop_var: secgroup_name
#
#- name: Create securiy group rules
# include: zonerecord_create.yml
# with_items:
# - "{{ secgroups }}"
# loop_control:
# loop_var: secgroup_name
- name: Create zonerecords
include: zonerecord_create.yml
with_items:
- "{{ zone_records }}"
loop_control:
loop_var: zone_name
2 changes: 1 addition & 1 deletion roles/otc_dns/tasks/delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
when: zone_id is defined
when: zone_id is defined and zone_id|length != 0
register: zone

- debug: var=zone.json
Expand Down
26 changes: 21 additions & 5 deletions roles/otc_dns/tasks/list.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
- name: Send request to API (list zone)
- name: Send request to API (list public zone)
uri:
url: "{{ AUTH_URL_DNS }}/v2/zones"
url: "{{ AUTH_URL_DNS }}/v2/zones?type=public"
method: GET
return_content: yes
validate_certs: yes
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
when: zone_id is undefined
register: zonelist
register: zonelist_public

- debug: var=zonelist.json
- name: Send request to API (list private zones)
uri:
url: "{{ AUTH_URL_DNS }}/v2/zones?type=private"
method: GET
return_content: yes
validate_certs: yes
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
register: zonelist_private

- name: Set fact zonelist
set_fact:
zonelist: "{{ zonelist_public.json.zones }} + {{ zonelist_private.json.zones }}"

- name: List zones
debug:
msg: "{{ zonelist }}"
when: zonelist is defined
29 changes: 21 additions & 8 deletions roles/otc_dns/tasks/lookup.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
- name: Send request to API (list zones)
- name: Send request to API (list public zones)
uri:
url: "{{ AUTH_URL_DNS }}/v2/zones"
url: "{{ AUTH_URL_DNS }}/v2/zones?type=public"
method: GET
return_content: yes
validate_certs: yes
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
when: zone_name is defined
register: zonelist_result
register: zonelist_public

- name: Set fact zonenamedot
- name: Send request to API (list private zones)
uri:
url: "{{ AUTH_URL_DNS }}/v2/zones?type=private"
method: GET
return_content: yes
validate_certs: yes
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
when: zone_name is defined
register: zonelist_private

- name: Set fact zonelist_result
set_fact:
zonenamedot: "{{ zone_name }}."
zonelist_result: "{{ zonelist_public.json.zones }} + {{ zonelist_private.json.zones }}"

- name: Set fact zone_id for dns if zone_name is defined
vars:
zonenamedot: "{{ zone_name }}."
set_fact:
zone_id: "{{ (zonelist_result.content|from_json)|json_query(\"zones[?name=='\" + zone_name + \"'].id|[0]\") }}"
zone_id: "{{ zonelist_result|json_query(\"[?name=='\" + zonenamedot + \"'].id|[0]\") }}"
when: zone_name is defined

- name: DEBUG zone_id
debug: var=zonenlist_result
- name: Debug zone_id
debug:
msg: "{{ zone_id }}"
23 changes: 22 additions & 1 deletion roles/otc_dns/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
tags:
- zonelist

- name: Get PTR list
include: ptr_list.yml
when:
- localaction is defined and localaction == "ptrlist"
tags:
- ptrlist

- name: Get Zone detail
include: show.yml
when:
Expand All @@ -19,8 +26,15 @@
tags:
- zonecreate

- name: Create PTR
include: ptr_create.yml
when:
- localaction is defined and localaction == "ptrcreate"
tags:
- ptrcreate

- name: Create Zonerecords
include: rule_create.yml
include: zonerecord_create.yml
when:
- localaction is defined and localaction == "zonerecordcreate"
tags:
Expand All @@ -32,3 +46,10 @@
- localaction is defined and localaction == "delete"
tags:
- zonedelete

- name: Delete PTR
include: ptr_delete.yml
when:
- localaction is defined and localaction == "ptrdelete"
tags:
- ptrdelete
37 changes: 37 additions & 0 deletions roles/otc_dns/tasks/ptr_create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- name: Send request to API (list EIP)
uri:
url: "{{ AUTH_URL_VPC }}/v1/{{ PROJECT_ID }}/publicips"
method: GET
return_content: yes
validate_certs: yes
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
register: floatingiplist_result

- name: Set fact eip_id if public_ip_address is defined
set_fact:
eip_id: "{{ (floatingiplist_result.content|from_json)|json_query(\"publicips[?public_ip_address=='\" + public_ip_address + \"'].id|[0]\") }}"
when:
- (public_ip_address is defined and public_ip_address | ipaddr)

- name: Send request to API (create ptr)
uri:
url: "{{ AUTH_URL_DNS }}/v2/reverse/floatingips/{{ PROJECT_NAME }}:{{ eip_id }}"
method: PATCH
body_format: raw
follow_redirects: all
return_content: yes
validate_certs: yes
status_code: 200,201,202,203,400
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
body: "{{ lookup('template', 'ptr_create.json.j2')|to_json }}"
register: ptrrecord
when:
- (ptr_name is defined and ptr_name | length != 0)
- eip_id is defined

- debug:
msg: "{{ ptrrecord }}"
37 changes: 37 additions & 0 deletions roles/otc_dns/tasks/ptr_delete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- name: Send request to API (list EIP)
uri:
url: "{{ AUTH_URL_VPC }}/v1/{{ PROJECT_ID }}/publicips"
method: GET
return_content: yes
validate_certs: yes
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
register: floatingiplist_result

- name: Set fact eip_id if public_ip_address is defined
set_fact:
eip_id: "{{ (floatingiplist_result.content|from_json)|json_query(\"publicips[?public_ip_address=='\" + public_ip_address + \"'].id|[0]\") }}"
when:
- (public_ip_address is defined and public_ip_address | ipaddr)


- name: Send request to API (delete ptr)
uri:
url: "{{ AUTH_URL_DNS }}/v2/reverse/floatingips/{{ PROJECT_NAME }}:{{ eip_id }}"
method: PATCH
body_format: raw
follow_redirects: all
return_content: yes
validate_certs: yes
status_code: 200,201,202,203,400
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
body: '{ "ptrdname": null }'
register: ptrrecord
when:
- eip_id is defined

- debug:
msg: "{{ ptrrecord }}"
15 changes: 15 additions & 0 deletions roles/otc_dns/tasks/ptr_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: Send request to API (list ptr)
uri:
url: "{{ AUTH_URL_DNS }}/v2/reverse/floatingips"
method: GET
follow_redirects: all
return_content: yes
validate_certs: yes
status_code: 200,201,202,203,400
headers:
Content-Type: "application/json"
X-Auth-Token: "{{ token['x_subject_token'] }}"
register: ptrrecord

- debug:
msg: "{{ ptrrecord }}"
Loading

0 comments on commit 27e1b4b

Please sign in to comment.