In this exercise, you will customize two instances using cloud-init capabilities and features. You will log in to the instances to confirm cloud-init is up and running, and verify that cloud-init has correctly customized the two instances.
Outcomes
You should be able to customize an instance using a cloud-config script or file and verify cloud-init operations by checking the /var/log/cloud-init.log file or that the requested customization has occurred.
Confirm that the workstation and overcloud's virtual machines are started.
Log in to workstation as student using student as the password.
On workstation, run the lab cloudapps-cloudinit start command.
[student@workstation ~]$ lab cloudapps-cloudinit start
Procedure 8.1. Instructions
Customize an instance using the Dashboard. Log in to the Dashboard using Example as the domain, developer1 as the user, and redhat as the password. Click the Project menu in the upper-right corner and ensure that finance is the current project. Launch an instance named finance-server1 with the rhel8 image, the default flavor, the finance-network1 network, the default security group, and the example-keypair key pair. Create a customization script that includes "Hello world!" in the /root/hello.txt file in the instance.
On workstation, open a web browser and navigate to http://dashboard.overcloud.example.com. Log in to the Dashboard using Example as the domain, developer1 as the user, and redhat as the password.
Navigate to → and then click .
On the tab, enter finance-server1 as the .
On the tab, choose in the field. Set to No. In the section, click the up arrow for the rhel8-web image.
On the tab, in the section, click the up arrow for the default flavor.
On the tab, in the section, click the up arrow for the finance-network1 network.
On the tab, ensure that the default security group has been selected.
On the tab, ensure that the example-keypair key pair has been selected.
On the tab, add the following content to the field, and then click :
#!/bin/sh echo 'Hello world!' > /root/hello.txt
When the instance is active, attach a floating IP address to the finance-server1 instance.
When the instance status changes to Active, attach a floating IP address to it. In the menu for the instance, click .
section, click to create a new floating IP address. Click and then click .
Sign out of the Dashboard.
On workstation, source the developer1-finance-rc file and create a user-data file, called install_httpd, to customize the instance. The script will install the web server and enable the service.
[student@workstation ~]$source developer1-finance-rc[student@workstation ~(developer1-finance)]$vim /home/student/install_httpd#!/bin/bash # web server with a postgres backend yum -y install httpd python3-psycopg2 systemctl enable httpd --now
This script will install and enable the web server service.
Customize an instance using the command line. As the developer1 user launch an instance named finance-server2 with the rhel8-web image, the default flavor, the finance-network1 network, the default security group, and the example-keypair key pair. Include the /home/student/install_httpd user-data script.
Launch an instance using the --user-data option to perform the customization.
[student@workstation ~(developer1-finance)]$openstack server create \>--image rhel8-web \>--flavor default \>--nic net-id=finance-network1 \>--security-group default \>--key-name example-keypair \>--user-data /home/student/install_httpd \>--wait finance-server2...output omitted...
Verify that the status of the finance-server2 instance is active.
[student@workstation ~(developer1-finance)]$openstack server list \>-c Name -c Status -c Networks+-----------------+--------+------------------------------------------------+ | Name | Status | Networks | +-----------------+--------+------------------------------------------------+ | finance-server2 |ACTIVE| finance-network1=192.168.1.80 | | finance-server1 | ACTIVE | finance-network1=192.168.1.168, 172.25.250.105 | +-----------------+--------+------------------------------------------------+
When the instance state is active, create a new floating IP address and attach it to the instance. Verify that the floating IP has been assigned. Note that the IP addresses are provided from a pool and will be different each time.
[student@workstation ~(developer1-finance)]$openstack floating ip create \>provider-datacentre+---------------------+------------------------------------------+ | Field | Value | +---------------------+------------------------------------------+ | created_at | 2020-07-29T01:54:06Z | | description | | | dns_domain | | | dns_name | | | fixed_ip_address | None | | floating_ip_address | 172.25.250.106 | | floating_network_id | aa59f24c-117a-43d3-bcda-421e40e074b7 | | id | c7dee859-39be-490b-8ca4-e11b893dfb34 | | location | Munch({'cloud': '', 'region_name': | | | 'regionOne', 'zone': None, 'project': | | | Munch({'id': | | | '5916c863837d4f9dbfe8ce523bef489d', | | | 'name': 'finance', 'domain_id': None, | | | 'domain_name': 'Example'})}) | | name | 172.25.250.155 | | port_details | None | | port_id | None | | project_id | 5916c863837d4f9dbfe8ce523bef489d | | qos_policy_id | None | | revision_number | 0 | | router_id | None | | status | DOWN | | subnet_id | None | | tags | [] | | updated_at | 2020-07-29T01:54:06Z | +---------------------+------------------------------------------+ [student@workstation ~(developer1-finance)]$openstack server add floating ip \>finance-server2 172.25.250.106[student@workstation ~(developer1-finance)]$openstack server list \>-c Name -c Networks+-----------------+--------+------------------------------------------------+ | Name | Status | Networks | +-----------------+--------+------------------------------------------------+ | finance-server2 | ACTIVE | finance-network1=192.168.1.80, 172.25.250.106 | | finance-server1 | ACTIVE | finance-network1=192.168.1.168, 172.25.250.105 | +-----------------+--------+------------------------------------------------+
Log in to finance-server1 to verify that the cloud-init customization script created the /root/hello.txt file.
Log in to finance-server1 with ssh using the example-keypair private key.
[student@workstation ~(developer1-finance)]$ssh -i ~/.ssh/example-keypair \>cloud-user@172.25.250.105
Verify within /var/log/cloud-init.log to confirm that cloud-init ran.
[cloud-user@finance-server1 ~]$ sudo less /var/log/cloud-init.log
...output omitted...
...util.py[DEBUG]: Cloud-init v. 18.5 finished at Wed, 29 Jul 2020 01:46:23 +0000. Datasource DataSourceOpenStack [net,ver=2]. Up 60.75 secondsEnsure that the /root/hello.txt file exists and has the correct content.
[cloud-user@finance-server1 ~]$ sudo cat /root/hello.txt
Hello world!Log out from finance-server1.
[cloud-user@finance-server1 ~]$ exit
logout
Connection to 172.25.250.105 closed.Log in to finance-server2 to verify that the /home/student/install_httpd user-data script installed and enabled the httpd service.
Determine the floating IP address allocated to the finance-server2 instance.
[student@workstation ~(developer1-finance)]$openstack server show \>finance-server2 -c addresses -f valuefinance-server2=192.168.1.80,172.25.250.106
Using ssh and the example-keypair private key, log in to finance-server2.
[student@workstation ~(developer1-finance)]$ssh -i ~/.ssh/example-keypair \>cloud-user@172.25.250.106
Verify within /var/log/cloud-init.log to confirm that cloud-init ran.
[cloud-user@finance-server2 ~]$ sudo less /var/log/cloud-init.log
...output omitted...
...util.py[DEBUG]: Cloud-init v. 18.5 finished at Wed, 29 Jul 2020 01:53:25 +0000. Datasource DataSourceOpenStack [net,ver=2]. Up 65.32 secondsConfirm that httpd is working.
[cloud-user@finance-server2 ~]$ curl http://localhost | grep Test
<title>Test Page for the Apache HTTP Server on Red Hat Enterprise Linux</title>
<h1>Red Hat Enterprise Linux <strong>Test Page</strong></h1>On workstation, use the curl command to navigate to http://172.25.250.106. The connection must succeed.
[student@workstation ~(developer1-finance)]$ curl http://172.25.250.106
...output omitted...This concludes the guided exercise.