-1

I am trying to install several kvm's with ansible and virt-install using kickstart file.

tasks:
- name: Create VMs 
  command: /usr/bin/virt-install --connect=qemu:///system --network network=default 
  --initrd-inject=/tmp/anaconda-ks.cfg 
  --extra-args="console=tty0 console=ttyS0,115200 serial rd_NO_PLYMOUTH ks=file:/anaconda-ks.cfg" 
  --name={{ item }} 
  --disk path=/var/lib/libvirt/images/{{ item }}.qcow2,format=qcow2,size=10,cache=none 
  --ram 1024 --vcpus=1 --check-cpu --accelerate 
  --os-type linux --os-variant fedora19 --hvm 
  --location=/tmp/Fedora-20-x86_64-DVD.iso --nographics
  with_items:
    - vm1
    - vm2
    - vm3

The question is how to make "--hostname= {{ item }}" in kickstart file (/tmp/anaconda-ks.cfg) replaced dynamically for each vm. So that after install each vm will be with its own hostname.

Igor Zilberman
  • 1,048
  • 1
  • 11
  • 16
  • 1
    Have a look at the `template` or `lineinfile` modules - either one of those can do that. Which one works best in this case depends on the structure of the file. – nikobelia Dec 10 '16 at 23:22

1 Answers1

0

Well, as suggested by @nikobelia I used a template

 - name: Create template  
   template: src=templates/anaconda-ks-jenkins.j2 dest=/tmp/anaconda-ks-{{ item }}.cfg
   with_items: "{{ groups.all }}"

where groups.all is all hosts in inventory (hosts) file. So for each host it replaced {{ item }}, inside the template itself, with a hostname

Igor Zilberman
  • 1,048
  • 1
  • 11
  • 16