Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- # This playbook creates VM from the QCOW2 Image
- - name: Create VM Playbook
- hosts: localhost
- become: yes
- become_method: sudo
- vars_files:
- - vars/guests.yml
- tasks:
- - name: Start libvirtd
- service: name=libvirtd state=started enabled=yes
- register: libvirtd
- - name: Wait for libvirtd to start
- wait_for:
- timeout: 30
- when: libvirtd.changed
- - name: Create domain message display
- shell: echo 'Creating domain "{{ item.domain }}"'
- with_items: guests
- - name: Create tmpdir for cloud-init
- shell:
- mktemp -d
- register: tmpdir
- - debug: msg="{{ tmpdir.stdout }}"
- - name: Create cloud-init meta-data and user-data destinations
- file: path={{ item }} state=touch
- with_items:
- - "{{ tmpdir.stdout }}"/meta-data
- - "{{ tmpdir.stdout }}"/user-data
- - name: cloud-init meta-data
- lineinfile: dest="{{ tmpdir.stdout }}"/meta-data line='instance-id{{':'}} "{{ item.domain }}"-iid\nlocal-hostname{{':'}} "{{ item.domain }}"'
- with_items: guests
- - name: cloud-init user-data
- lineinfile: dest="{{ tmpdir.stdout }}"/user-data line='user{{':'}} atomic-user\npassword{{':'}} atomic\nchpasswd{{':'}} {expire{{':'}} False}\nssh_pwauth{{':'}} True'
- - name: Create a cloud-init metadata ISO Image
- shell: genisoimage -input-charset default
- -output "{{ item.path }}"/"{{ item.domain }}".cidata.iso
- -volid "{{ item.path }}"/"{{ item.domain }}".cidata.iso
- -joliet
- -rock
- -quiet
- "{{ tmpdir.stdout }}"/user-data
- "{{ tmpdir.stdout }}"/meta-data
- with_items: guests
- - name: Create VM from QCOW2
- shell: virt-install --quiet --install --name="{{ item.domain }}"
- --os-variant="{{ item.os.variant }}" --ram="{{ item.mem }}"
- --vcpus="{{ item.cpu }}" --disk path="{{ item.path }}"/"{{ item.domain }}".qcow2,
- format=qcow2,bust=virtio --disk path="{{ item.path }}"/"{{ item.domain }}".cidata.iso,
- device=cdrom,readonly=on --network network=default --noautoconsole
- with_items: guests
- - name: Make sure that the VM is running
- virt: name="{{ item.domain }}" command=start
- with_items: guests
- - name: Display username and password
- shell:
- echo "You can log in with username: atomic-user/password:atomic"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement