Add ansible role for dns simulation 25/74925/1
authorTomáš Levora <t.levora@partner.samsung.com>
Wed, 19 Dec 2018 14:47:04 +0000 (15:47 +0100)
committerTomáš Levora <t.levora@partner.samsung.com>
Wed, 19 Dec 2018 14:50:00 +0000 (15:50 +0100)
Adding role to simulate domain names for offline installation from
private nexus repositories

Issue-ID: OOM-1551

Change-Id: Ia3fe274e95ef078332627af9229195bd6e9a667d
Signed-off-by: Tomáš Levora <t.levora@partner.samsung.com>
ansible/roles/dns/handlers/main.yml [new file with mode: 0644]
ansible/roles/dns/tasks/main.yml [new file with mode: 0644]
ansible/roles/dns/templates/simulated_hosts.j2 [new file with mode: 0644]

diff --git a/ansible/roles/dns/handlers/main.yml b/ansible/roles/dns/handlers/main.yml
new file mode 100644 (file)
index 0000000..ac3209d
--- /dev/null
@@ -0,0 +1,14 @@
+---
+- name: Restart dnsmasq container
+  docker_container:
+    name: dnsmasq
+    image: andyshinn/dnsmasq:2.76
+    command: -H /simulated_hosts --log-facility=-
+    capabilities: NET_ADMIN
+    volumes:
+      - "{{ app_data_path }}/cfg/simulated_hosts:/simulated_hosts:ro"
+    ports:
+      - "53:53/tcp"
+      - "53:53/udp"
+    state: started
+    restart_policy: unless-stopped
diff --git a/ansible/roles/dns/tasks/main.yml b/ansible/roles/dns/tasks/main.yml
new file mode 100644 (file)
index 0000000..2bc0564
--- /dev/null
@@ -0,0 +1,36 @@
+---
+- name: Ensure cfg directory exist
+  file:
+    path: "{{ app_data_path }}/cfg"
+    state: directory
+
+- name: Create simulated hostnames file
+  template:
+    src: simulated_hosts.j2
+    dest: "{{ app_data_path }}/cfg/simulated_hosts"
+  notify: Restart dnsmasq container
+
+- name: Load dnsmasq container
+  docker_image:
+    name: andyshinn/dnsmasq:2.76
+    load_path: "{{ app_data_path }}/offline_data/docker_images_infra/andyshinn_dnsmasq_2.76.tar"
+    state: present
+    timeout: 120
+  notify: Restart dnsmasq container
+
+- name: Start dnsmasq container
+  docker_container:
+    name: dnsmasq
+    network_mode: host
+    image: andyshinn/dnsmasq:2.76
+    command: -H /simulated_hosts --log-facility=-
+    capabilities: NET_ADMIN
+    dns_servers:
+      - 127.0.0.1
+    volumes:
+      - "{{ app_data_path }}/cfg/simulated_hosts:/simulated_hosts:ro"
+    ports:
+      - "53:53/tcp"
+      - "53:53/udp"
+    state: started
+    restart_policy: unless-stopped
diff --git a/ansible/roles/dns/templates/simulated_hosts.j2 b/ansible/roles/dns/templates/simulated_hosts.j2
new file mode 100644 (file)
index 0000000..637aef6
--- /dev/null
@@ -0,0 +1,3 @@
+{% for host in all_simulated_hosts -%}
+        {{ ansible_host }} {{ host }}
+{% endfor %}