How to run a virtual CentOS 6 in few steps

Simple and easy way how to access a CentOS 6 system locally using qemu and CentOS cloud image.

Prepare an image

We need to do some steps in order to be able to access CentOS cloud image:

$ cat > user-data <<EOF
#cloud-config
user: admin
password: foobar
ssh_pwauth: True
chpasswd:
  expire: False
ssh_authorized_keys:
  - `ssh-add -L | head -n 1`
EOF

$ cat > meta-data <<EOF
instance-id: nocloud
local-hostname: system-api-test
EOF

$ genisoimage -input-charset utf-8 -output cloudinit_iso -volid cidata \
-joliet -rock -quiet user-data meta-data

$ wget https://cloud.centos.org/centos/6/images/CentOS-6-x86_64-GenericCloud-1702.qcow2c

Run the image

The image is run using qemu

$ qemu-system-x86_64 -m 1024 CentOS-6-x86_64-GenericCloud-1702.qcow2c -snapshot \
-cdrom cloudinit_iso -net nic,model=virtio -net user,hostfwd=tcp::2222-:22 \
-display none -enable-kvm

Access the image using ssh and Ansible

$ ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-o PasswordAuthentication=no admin@localhost -p 2222
arning: Permanently added '[localhost]:2222' (RSA) to the list of known hosts.
[admin@system-api-test ~]$
$ ansible-playbook -u admin -i localhost:2222, \
--ssh-common-args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
test_selinux_disabled.yml

Receive Updates

ATOM