generate inventory file and ssh configuration file 49/53049/2
authorzhihui wu <wu.zhihui1@zte.com.cn>
Sun, 4 Mar 2018 08:23:58 +0000 (16:23 +0800)
committerzhihui wu <wu.zhihui1@zte.com.cn>
Tue, 6 Mar 2018 06:25:50 +0000 (14:25 +0800)
Generate inventory file and ssh configuration file for VM.
The default image is ubuntu 16.04. So the ansible user is
ubuntu.

Change-Id: Ie14ebcdcfbc24f045ffd32785eec07df5798c5fb
Signed-off-by: zhihui wu <wu.zhihui1@zte.com.cn>
resources/ansible_roles/openstack/defaults/main.yml
resources/ansible_roles/openstack/tasks/main.yml
resources/ansible_roles/openstack/templates/hosts.j2 [new file with mode: 0644]
resources/ansible_roles/openstack/templates/ssh.cfg.j2 [new file with mode: 0644]

index 830def6..261504e 100644 (file)
@@ -16,3 +16,4 @@ temp_dir: /tmp/qtip
 flavor_name: qtip_flavor
 stack_name: qtip_stack
 image_name: qtip_image
+ansible_user: ubuntu
index ed04383..6fabfb0 100644 (file)
       flavor: "{{ flavor_name }}"
       keypair: QtipKey
       external_network: "{{ external_network }}"
+  register: stack
+
+- name: generating inventory file
+  template:
+    src: hosts.j2
+    dest: ./hosts
+
+- name: generating ssh.cfg
+  template:
+    src: ssh.cfg.j2
+    dest: ./ssh.cfg
diff --git a/resources/ansible_roles/openstack/templates/hosts.j2 b/resources/ansible_roles/openstack/templates/hosts.j2
new file mode 100644 (file)
index 0000000..6756d2a
--- /dev/null
@@ -0,0 +1,17 @@
+localhost   ansible_connection=local
+
+[SUT:children]
+compute
+
+[node-groups:children]
+compute
+
+[node-groups:vars]
+ansible_ssh_common_args=-F ./ssh.cfg
+
+[compute]
+{% for item in stack.stack.outputs %}
+{% if item.output_key == 'instance_ip' %}
+{{item.output_value}}
+{% endif %}
+{% endfor %}
diff --git a/resources/ansible_roles/openstack/templates/ssh.cfg.j2 b/resources/ansible_roles/openstack/templates/ssh.cfg.j2
new file mode 100644 (file)
index 0000000..c0a1f94
--- /dev/null
@@ -0,0 +1,11 @@
+# Connect to target node 
+
+{% for item in stack.stack.outputs %}
+{% if item.output_key == 'instance_ip' %}
+Host {{ item.output_value }}
+  HostName {{ item.output_value }}
+  User {{ ansible_user }}
+  IdentityFile {{ temp_dir }}/QtipKey
+{% endif %}
+
+{% endfor %}