This example creates a Virtual Server Instance (VSI) inside of a Virtual Private Cloud (VPC). The VSI is configured to allow incoming SSH connections through a publicly accessible IP address and authenticated using an SSH key pair.
The following VPC infrastructure resources will be created (Ansible modules in parentheses):
- VPC (ibm_is_vpc)
- Subnet (ibm_is_subnet)
- VSI (ibm_is_instance)
- Floating IP Address (ibm_is_floating_ip)
- Security Group Rule (ibm_is_security_group_rule)
The following parameters can be set by the user:
name_prefix
: Prefix used to name created resourcesvsi_image
: VSI image name (retrieve available images)vsi_profile
: VSI profile name (retrieve available profiles)ssh_public_key
: SSH Public Keyipv4_cidr_block
: IPv4 CIDR Block for VPC Subnetzone
: IBM Cloud zone
Note: Alternate install path is to use 'examples/install_modules.yml' playbook.
-
Download IBM Cloud Ansible modules from release page
-
Extract module archive.
unzip ibmcloud_ansible_modules.zip
-
Add modules and module_utils to the Ansible search path. E.g.:
cp build/modules/* $HOME/.ansible/plugins/modules/. cp build/module_utils/* $HOME/.ansible/plugins/module_utils/.
-
Export your API key to the
IC_API_KEY
environment variable:export IC_API_KEY=<YOUR_API_KEY_HERE>
Note: Modules also support the 'ibmcloud_api_key' parameter, but it is recommended to only use this when encrypting your API key value.
-
Export desired IBM Cloud region to the 'IC_REGION' environment variable:
export IC_REGION=<REGION_NAME_HERE>
Note: Modules also support the 'ibmcloud_region' parameter.
-
To create all resources and test public SSH connection to the VM, run the 'create' playbook:
ansible-playbook create.yml
-
To destroy all resources run the 'destroy' playbook:
ansible-playbook destroy.yml
-
To destroy all resources run the 'destroy' playbook:
ansible-playbook list_vsi_images_and_profiles.yml