Created
April 29, 2021 13:05
-
-
Save Finkregh/c24d562e8ae226b0c5c11feb604fb108 to your computer and use it in GitHub Desktop.
Ansible: create OpenStack VM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Deploy on OpenStack | |
hosts: localhost | |
gather_facts: false | |
tasks: | |
- name: get OS server info | |
os_server_info: | |
server: "fedora-from-ansible" | |
register: instance_state | |
ignore_errors: true | |
- name: Deploy an instance | |
os_server: | |
state: present | |
name: fedora-from-ansible | |
image: IMAGE_ID | |
key_name: id_kitchen | |
wait: true | |
flavor: m1.xsmall | |
auto_ip: true | |
network: some_network | |
meta: | |
hostname: fedora-from-ansible | |
register: fedora_from_ansible | |
when: instance_state is not defined | |
- name: Add Fedora Instance to Inventory | |
add_host: name=fedora_from_ansible groups=fedora_from_ansibles | |
ansible_ssh_host={{ fedora_from_ansible.server.public_v4 }} | |
ansible_ssh_private_key_file=~/somekey | |
when: instance_state is not defined | |
- name: Add Fedora Instance to Inventory | |
add_host: name=fedora_from_ansible groups=fedora_from_ansibles | |
ansible_ssh_host={{ instance_state.openstack_servers[0].accessIPv4 }} | |
ansible_ssh_private_key_file=~/somekey | |
when: instance_state | |
- hosts: fedora_from_ansibles | |
remote_user: fedora | |
become: true | |
tasks: | |
- name: Wait for system to become reachable via SSH | |
wait_for_connection: | |
timeout: 9000 | |
- name: Gather facts for first time | |
setup: | |
- name: upgrade all packages | |
dnf: | |
name: "*" | |
state: latest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment