mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
add ansible script to create a Win VM (#5288)
* add ansible script to create a Win VM Signed-off-by: anandrkskd <anandrkskd@gmail.com> * add sshkey_id var Signed-off-by: anandrkskd <anandrkskd@gmail.com> * move comment to var.yaml Signed-off-by: anandrkskd <anandrkskd@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e4e26f55be
commit
7329934c02
113
scripts/ansible/kubernetes-cluster/create-vm.yml
Normal file
113
scripts/ansible/kubernetes-cluster/create-vm.yml
Normal file
@@ -0,0 +1,113 @@
|
||||
---
|
||||
- name: Create IBM Cloud VPC VSI
|
||||
hosts: localhost
|
||||
collections:
|
||||
- ibm.cloudcollection
|
||||
tasks:
|
||||
- name: Fetch the variables from var file
|
||||
include_vars:
|
||||
file: vars.yml
|
||||
|
||||
- name: Configure VPC
|
||||
ibm_is_vpc:
|
||||
name: "{{ name_prefix }}-vpc"
|
||||
state: available
|
||||
id: "{{ vpc.id | default(omit) }}"
|
||||
register: vpc_create_output
|
||||
|
||||
- name: Save VPC as fact
|
||||
set_fact:
|
||||
cacheable: True
|
||||
vpc: "{{ vpc_create_output.resource }}"
|
||||
|
||||
- name: Configure VPC Subnet
|
||||
ibm_is_subnet:
|
||||
name: "{{ name_prefix }}-subnet"
|
||||
state: available
|
||||
id: "{{ subnet.id | default(omit) }}"
|
||||
vpc: "{{ vpc.id }}"
|
||||
total_ipv4_address_count: "{{ total_ipv4_address_count }}"
|
||||
zone: "{{ cluster_zone }}"
|
||||
register: subnet_create_output
|
||||
|
||||
- name: Save VPC Subnet as fact
|
||||
set_fact:
|
||||
cacheable: True
|
||||
subnet: "{{ subnet_create_output.resource }}"
|
||||
|
||||
# NOTE: Uncomment in case we want to create and use a new sshkey
|
||||
# - name: Configure SSH Key
|
||||
# ibm_is_ssh_key:
|
||||
# name: "{{ name_prefix }}-ssh-key"
|
||||
# public_key: "{{ ssh_public_key }}"
|
||||
# id: "{{ ssh_key.id | default(omit) }}"
|
||||
# register: ssh_key_create_output
|
||||
|
||||
# - name: Save SSH Key as fact
|
||||
# set_fact:
|
||||
# cacheable: True
|
||||
# ssh_key: "{{ ssh_key_create_output.resource }}"
|
||||
|
||||
- name: Retrieve image list
|
||||
ibm_is_images_info:
|
||||
register: images_list
|
||||
|
||||
- name: Set VM image name/id dictionary fact
|
||||
set_fact:
|
||||
cacheable: True
|
||||
image_dict: "{{ images_list.resource.images |
|
||||
items2dict(key_name='name', value_name='id') }}"
|
||||
|
||||
- name: Configure VSI
|
||||
ibm_is_instance:
|
||||
name: "{{ name_prefix }}-windows-vsi"
|
||||
state: available
|
||||
id: "{{ vsi.id | default(omit) }}"
|
||||
vpc: "{{ vpc.id }}"
|
||||
profile: "{{ vsi_profile }}"
|
||||
image: "{{ image_dict[vsi_image] }}"
|
||||
keys:
|
||||
- " {{ sshkey_id }} "
|
||||
primary_network_interface:
|
||||
- subnet: "{{ subnet.id }}"
|
||||
zone: "{{ cluster_zone }}"
|
||||
register: vsi_create_output
|
||||
|
||||
- name: Save VSI as fact
|
||||
set_fact:
|
||||
cacheable: True
|
||||
vsi: "{{ vsi_create_output.resource }}"
|
||||
|
||||
- name: Configure Floating IP Address
|
||||
ibm_is_floating_ip:
|
||||
name: "{{ name_prefix }}-fip"
|
||||
state: available
|
||||
id: "{{ fip.id | default(omit) }}"
|
||||
target: "{{ vsi.primary_network_interface[0]['id'] }}"
|
||||
register: fip_create_output
|
||||
|
||||
- name: Save Floating IP as fact
|
||||
set_fact:
|
||||
cacheable: True
|
||||
fip: "{{ fip_create_output.resource }}"
|
||||
|
||||
- name: Print Floating IP Address
|
||||
debug:
|
||||
msg: "IP Address: {{ fip.address }}"
|
||||
|
||||
- name: Configure Security Group Rule to open SSH on the VSI
|
||||
ibm_is_security_group_rule:
|
||||
state: available
|
||||
group: "{{ vpc.default_security_group }}"
|
||||
direction: inbound
|
||||
remote: 0.0.0.0/0
|
||||
tcp:
|
||||
- port_max: 22
|
||||
port_min: 22
|
||||
|
||||
- name: Add VSI to Ansible inventory
|
||||
add_host:
|
||||
name: "{{ fip.address }}"
|
||||
ansible_user: root
|
||||
groups: new_vsi
|
||||
ansible_ssh_extra_args: -o StrictHostKeyChecking=no
|
||||
@@ -7,3 +7,6 @@ node_flavor: bx2.4x16
|
||||
workers: 3
|
||||
nfs_image: ibm-ubuntu-20-04-2-minimal-amd64-1
|
||||
ssh_public_key: AAAAB3NzaC1yc2EAAAADAQABAAABgQCkFJaWm3EMxPLf/JMfJamXeVrsOQBgKe4F7thRZ5RYYmA0a9owJ9pievDPB459K7EWBNYZH1UtuG9ipCR25Y8baDZ5XWnK4e3z4nNhEbMxUnS2or52JCuix6LBbYEbsgLPPiof8kXUEKUGvzfJ0vASFcrF9XKMnQ789A9ee8BMd0SZMAs2Jp2wQ3gjzyg4ZpQvfmQ0ua4EVDu3RItSba8F5cfgGLVQPj+4K+WHfQf0jG7ew5F7LolfdjgAj041RbpYZx8SNDxdsoi06rttn92aEUgutGDHaa/P4JhuFZg4IRFwqDrEEyLuEhP89DniWmTyewyetEScmu2gVmFSFfHzPx3L9pkOP/zDTRzuuOYXNmqNUH3nt/kOxxzzuubTiSpGCP3H9NgYzOQk2E4m94znFVb3fifXETL9kOsZQ90yMnRrYRSPSmAcIiFXSWAFUIQ4Y6aTMI2D1ZoS2gMniKRN3SldkH3UeuKq2jf7TZpDMSQCcPbwZN0Qe+uLt/fiQKM=
|
||||
vsi_image: odo-test-windows # Image ID: r010-1c3682a3-0013-496f-a663-9772f933d5be || this image is a private image and only available in Developer QE
|
||||
vsi_profile: bx2-2x8
|
||||
sshkey_id: r010-0f01beeb-9b45-4406-93bb-4a8604c8a3e0 # sshkey id ansible-ssh-key in developer qe group in VPC sshkey
|
||||
Reference in New Issue
Block a user