Skip to content

Instantly share code, notes, and snippets.

@amarao
Created April 18, 2018 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amarao/37c6c815cc391384b495ef7827286435 to your computer and use it in GitHub Desktop.
Save amarao/37c6c815cc391384b495ef7827286435 to your computer and use it in GitHub Desktop.
- hosts: all
gather_facts: no
serial: 1
tasks:
- name: Remove old facts
meta: clear_facts
- name:
set_fact:
host_v1: '{{ansible_ssh_host}}'
host_v2: '{{ansible_host}}'
tags:
- always
- name: Forcefully drop fact cache for host
local_action: file path=.facts/{{inventory_hostname}} state=absent
changed_when: True
- name: remove old server key
local_action: command ssh-keygen -R '{{host_v1}}'
failed_when: false
changed_when: True
- name: remove old server IP key
local_action: shell ssh-keygen -R `host {{host_v1}}|awk '{print $4}'`
failed_when: false
changed_when: True
- name: remove old server key
local_action: command ssh-keygen -R '{{host_v2}}'
failed_when: false
changed_when: True
- name: remove old server IP key
local_action: shell ssh-keygen -R `host {{host_v2}}|awk '{print $4}'`
failed_when: false
changed_when: True
- hosts: all
gather_facts: no
tasks:
- name: Remember sever key and install python
raw: test -x /usr/bin/python || sudo apt-get update && sudo apt-get -y install python
changed_when: True
vars:
ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment