summaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorzhihui wu <wu.zhihui1@zte.com.cn>2018-03-04 16:23:58 +0800
committerzhihui wu <wu.zhihui1@zte.com.cn>2018-03-06 14:25:50 +0800
commit8126d8250b7c7782d2a391d5bb450e784a31e857 (patch)
tree8cdbfde8bf12df39c826fad607a5622984078da5 /resources
parent44b6f29402625d1d29d482a5524efa27112886ce (diff)
generate inventory file and ssh configuration file
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>
Diffstat (limited to 'resources')
-rw-r--r--resources/ansible_roles/openstack/defaults/main.yml1
-rw-r--r--resources/ansible_roles/openstack/tasks/main.yml11
-rw-r--r--resources/ansible_roles/openstack/templates/hosts.j217
-rw-r--r--resources/ansible_roles/openstack/templates/ssh.cfg.j211
4 files changed, 40 insertions, 0 deletions
diff --git a/resources/ansible_roles/openstack/defaults/main.yml b/resources/ansible_roles/openstack/defaults/main.yml
index 830def62..261504ea 100644
--- a/resources/ansible_roles/openstack/defaults/main.yml
+++ b/resources/ansible_roles/openstack/defaults/main.yml
@@ -16,3 +16,4 @@ temp_dir: /tmp/qtip
flavor_name: qtip_flavor
stack_name: qtip_stack
image_name: qtip_image
+ansible_user: ubuntu
diff --git a/resources/ansible_roles/openstack/tasks/main.yml b/resources/ansible_roles/openstack/tasks/main.yml
index ed043831..6fabfb01 100644
--- a/resources/ansible_roles/openstack/tasks/main.yml
+++ b/resources/ansible_roles/openstack/tasks/main.yml
@@ -84,3 +84,14 @@
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
index 00000000..6756d2a2
--- /dev/null
+++ b/resources/ansible_roles/openstack/templates/hosts.j2
@@ -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
index 00000000..c0a1f94e
--- /dev/null
+++ b/resources/ansible_roles/openstack/templates/ssh.cfg.j2
@@ -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 %}