|
| 1 | +--- |
| 2 | +- name: Rekey hosts |
| 3 | + hosts: overcloud,seed,seed-hypervisor,infra-vms |
| 4 | + gather_facts: false |
| 5 | + vars: |
| 6 | + ansible_user: stack |
| 7 | + ansible_python_interpreter: /usr/bin/python3 |
| 8 | + tasks: |
| 9 | + - name: Generate a fresh SSH key |
| 10 | + community.crypto.openssh_keypair: |
| 11 | + path: ~/.ssh/id_rsa_new |
| 12 | + delegate_to: localhost |
| 13 | + |
| 14 | + # - name: Copy new key to hosts |
| 15 | + # ansible.builtin.copy: |
| 16 | + # src: /tmp/id_rsa_new.pub |
| 17 | + # dest: /tmp/id_rsa_new.pub |
| 18 | + # mode: '0600' |
| 19 | + # become: true |
| 20 | + |
| 21 | + - name: Copy old key to hosts |
| 22 | + ansible.builtin.copy: |
| 23 | + src: ~/.ssh/id_rsa.pub |
| 24 | + dest: /tmp/id_rsa_old.pub |
| 25 | + mode: '0777' |
| 26 | + become: true |
| 27 | + |
| 28 | + - name: Set new stack authorized keys |
| 29 | + ansible.posix.authorized_key: |
| 30 | + user: "{{ item }}" |
| 31 | + state: present |
| 32 | + key: "{{ lookup('file', '~/.ssh/id_rsa_new.pub') }}" |
| 33 | + loop: |
| 34 | + - "stack" |
| 35 | + - "kolla" |
| 36 | + become: true |
| 37 | + |
| 38 | + - name: Set new stack authorized keys |
| 39 | + ansible.posix.authorized_key: |
| 40 | + user: "{{ item }}" |
| 41 | + state: present |
| 42 | + key: "{{ lookup('file', '~/.ssh/id_rsa_new.pub') }}" |
| 43 | + loop: |
| 44 | + - "stack" |
| 45 | + - "kolla" |
| 46 | + become: true |
| 47 | + |
| 48 | + - name: Locally deprecate old key (private) |
| 49 | + command: "mv ~/.ssh/id_rsa ~/.ssh/id_rsa_old" |
| 50 | + delegate_to: localhost |
| 51 | + |
| 52 | + - name: Locally deprecate old key (public) |
| 53 | + command: "mv ~/.ssh/id_rsa.pub ~/.ssh/id_rsa_old.pub" |
| 54 | + delegate_to: localhost |
| 55 | + |
| 56 | + - name: Locally promote new key (private) |
| 57 | + command: "mv ~/.ssh/id_rsa_new ~/.ssh/id_rsa" |
| 58 | + delegate_to: localhost |
| 59 | + |
| 60 | + - name: Locally promote new key (public) |
| 61 | + command: " mv ~/.ssh/id_rsa_new.pub ~/.ssh/id_rsa.pub" |
| 62 | + delegate_to: localhost |
| 63 | + |
| 64 | + - name: Remove old key from hosts |
| 65 | + ansible.posix.authorized_key: |
| 66 | + user: "{{ item }}" |
| 67 | + state: absent |
| 68 | + key: "{{ lookup('file', '/tmp/id_rsa_old.pub') }}" |
| 69 | + loop: |
| 70 | + - "stack" |
| 71 | + - "kolla" |
| 72 | + become: true |
0 commit comments