I have a local playbook on my laptop which I use to build local vms for
testing. I have noticed recently (with the update to Ansible 2.9) that I
have been having issues with the playbook running successfully. It used to
work perfectly fine.
ansible version = ansible-2.9.4-1.el8ae.noarch
[]$ cat vars.yml
---
qcow_image: /home/name/KVM-Images/rhel-8.1-x86_64-kvm.qcow2
libvirt_path: /var/lib/libvirt/images
qemu_path: /usr/libexec/qemu-kvm
password: <removed>
vm_name: rhel8fixingbook
vm_domain: <removed>.local
vm_cpu: 2
vm_ram: 8192
vm_size: 40G
nameserver: "@192.168.122.1"
[]$ cat custom-vm.yml
---
- hosts: localhost
connection: local
become: true
gather_facts: false
vars_files:
- vars.yml
tasks:
- name: Copying Image to libvirt path
command: cp {{ qcow_image }} {{ libvirt_path }}/{{vm_name}}.qcow2
- name: Resizing VM
command: qemu-img resize {{ libvirt_path }}/{{ vm_name }}.qcow2 {{
vm_size }}
- name: Copy meta-data template to tmp
template:
src: templates/meta-data
dest: /tmp/meta-data
owner: root
group: root
mode: 0644
- name: Copy user-data template to tmp
template:
src: templates/user-data-custom
dest: /tmp/user-data
owner: root
group: root
mode: 0644
- name: Create config
command: genisoimage -o /tmp/config.iso -V cidata -r -J /tmp/meta-data
/tmp/user-data
- name: Create VM
virt:
name: "{{ vm_name }}"
command: define
xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"
uri: 'qemu:///system'
- name: Start VM
virt:
name: "{{ vm_name }}"
state: running
- name: Add config to VM
command: virsh change-media {{ vm_name }} hda /tmp/config.iso --insert
- pause:
seconds: 20
- name: Get IP Address of New VM
command: dig {{ vm_name }} {{ nameserver }} +short
register: vm_ipaddr
- name: Output New VM IPaddress
debug:
msg: "New VM IPaddress: {{ vm_ipaddr.stdout }}"
- name: Set VM IP Address Fact
set_fact:
new_vm_ipaddr: "{{ vm_ipaddr.stdout }}"
- hosts: "{{ hostvars['localhost']['new_vm_ipaddr'] }}"
become: true
tasks:
- include_role:
name: "{{ item }}"
with_items:
- reg_n_packs
# - ansible_tower
Play run (ansible-playbook -K custom-vm.yml):
.........
TASK [Get IP Address of New VM]
************************************************************************************************************
changed: [localhost]
TASK [Output New VM IPaddress]
*************************************************************************************************************
ok: [localhost] => {
"msg": "New VM IPaddress: 192.168.122.206"
}
TASK [Set VM IP Address Fact]
**************************************************************************************************************
ok: [localhost]
[WARNING]: Could not match supplied host pattern, ignoring: 192.168.122.206
PLAY [192.168.122.206]
*********************************************************************************************************************
skipping: no hosts matched
PLAY RECAP
*********************************************************************************************************************************
localhost : ok=12 changed=7 unreachable=0
failed=0 skipped=0 rescued=0 ignored=0
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/a90cc7f2-95bc-4041-8cb7-9d43a5fe85d1%40googlegroups.com.