This avoid relying on localconfig being used.
+++ /dev/null
-#!/bin/bash
-
-if [ -z "$1" ]; then
- echo "$0 <host>"
- exit 1
-fi
-
-SHORT="r3-${1%%.*}"
-SSH_HOST=$(ssh -G "$SHORT" | grep "^hostname " | awk '{ print($2) }' )
-
-for name in $SHORT $SSH_HOST; do
- ssh-keygen -f "$HOME/.ssh/known_hosts" -R "[$name]:22000"
-done
-
-exit 0
--- /dev/null
+#!/bin/sh
+set -eu
+
+if [ $# -eq 0 ]; then
+ echo "Usage: $0 vmname [vmname ...]" >&2
+ exit 1
+fi
+
+cd "$(dirname "$0")"
+
+for vmname in "$@"; do
+ ansible-playbook -e vmname="${vmname}" remove_known_hosts.yml
+done
--- /dev/null
+- name: Purge host from known hosts
+ hosts: localhost
+ gather_facts: no
+ tasks:
+ - command: ssh-keygen -f ~/.ssh/known_hosts -R [{{ item }}]:{{ hostvars[vmname].ansible_port }}
+ with_items:
+ - "{{ hostvars[vmname].ansible_host }}"
+ - r3-{{ vmname }}
+ - r3g-{{ vmname }}
+ - r3e-{{ vmname }}
+ - "{{ hostvars[vmname].vm_network_cooked.primary.ip }}"
echo "installing vm: $name with $distro/$codename"
echo ""
-echo "########## clearing old ssh host keys #########"
-./remove-known-host.sh "$name"
-echo ""
-
echo "######## running the install playbook ########"
exec ansible-playbook -e "vmname=$name" -e "vmdistro=$distro" -e "vmdistcodename=$codename" $@ vm-install.yml
group: _vmhost_
# TODO: add some sanity checks
+- import_playbook: remove_known_hosts.yml
+
- name: basic installation
hosts: _vmhost_
roles: