How to do it...

  1. For this, we need to have a key added to OpenStack before we boot the virtual machine. The name of the key has to be unique. This is what we will specify while booting an instance. So let's add our public key as follows:
- name: adding public key  os_keypair:    name: aditya    public_key: {{ aditya_pub_key }}
  1. We have used the variable for improving the readability of the code. It also helps if we need to change the keys quickly. We will add the value of the aditya_pub_key variable to the vars/main.yml file, as follows:
---aditya_pub_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbg83WYIxUfXWJ4bQiYfZYHceDwMJxnGfJqgYtHL/DAtegVY+Nm8MX3CRZYisfskt0m9CQ6y/Ux1OITTz+O11fgxLJcroZmKJbWW0K39gfHvFqR7FIe0zuJaxqUQUuyc0i6RCBRiZPiQQOPes2yDtfHgDWx3q9knS3ZXIAXcGLZrgfC1XnIK8CLAnZDved9Rue2bhsCnO9Mleh9g/CTtehMDAzD4NeSv9eETlHYkYSpJg8gFA3BFICpBxTqWSjf1mMQGSmiudFOhRjHIxL1Tvh+pnjSoL/jrLcP3RtMVuG0ZU0qkoAts1qpTwmyAJUz9Ts2EeyDJ0tXsFAiOFbmuMd ...

Get Ansible 2 Cloud Automation Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.