ansible/tasks/aws_cloud.yml

77 lines
2 KiB
YAML
Raw Normal View History

# Inspired by persistent_cloud.yml, but the VM is not started automatically.
# This only works with modern Fedora for now, not with RHEL/CentOS.
---
- include_vars: dir=/srv/web/infra/ansible/vars/all/ ignore_files=README
- name: check if the server is up, needs to be pre-started
local_action: shell nc -w 5 {{ inventory_hostname }} 22 < /dev/null
register: host_is_up
changed_when: false
check_mode: no
- name: birthday=on - drop the old known host entries
local_action: known_hosts path={{item}}
host={{ inventory_hostname }}
state=absent
with_items:
- /root/.ssh/known_hosts
when: birthday is defined
- name: gather the temporary ssh host key from the new instance
tasks/aws_cloud.yml: prefer ed25519 keys for now Seems like either the RHEL 8 (batcave) or Fedora 35 system (Fedora Copr Infra) prefers ed25519 keys over rsa, leading to weird auth problems: TASK [allow root ssh connections] *************************************************************************************************************************** Monday 29 November 2021 13:06:43 +0000 (0:00:00.314) 0:00:03.632 ******* Monday 29 November 2021 13:06:43 +0000 (0:00:00.314) 0:00:03.632 ******* fatal: [copr-be-dev.aws.fedoraproject.org]: UNREACHABLE! => {"changed": false, "msg": "Data could not be sent to remote host \"copr-be-dev.aws.fedoraproject.org\". Make sure this host can be reached over ssh: Certificate invalid: name is not a listed principal\r\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\r\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\nIT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\r\nSomeone could be eavesdropping on you right now (man-in-the-middle attack)!\r\nIt is also possible that a host key has just been changed.\r\nThe fingerprint for the ED25519 key sent by the remote host is\nSHA256:Cgs/aoJl9OJheAtZZ2CDiYx9ZeFMwD6dUYUJpPDTl58.\r\nPlease contact your system administrator.\r\nAdd correct host key in /root/.ssh/known_hosts to get rid of this message.\r\nOffending RSA key in /root/.ssh/known_hosts:21\r\nED25519 host key for copr-be-dev.aws.fedoraproject.org has changed and you have requested strict checking.\r\nHost key verification failed.\r\n", "unreachable": true} This lets us move forward with the tomorrow's update. The previous hack(s) were not OK.
2021-11-29 14:20:03 +01:00
local_action: command ssh-keyscan -t ed25519 {{ inventory_hostname }}
register: hostkey
when: birthday is defined
- name: add new ssh host key (until we can sign it)
local_action: known_hosts path={{item}} key="{{ hostkey.stdout }}"
host={{ inventory_hostname }} state=present
with_items:
- /root/.ssh/known_hosts
when: birthday is defined
# from https://github.com/praiskup/ansible-role-fix-root-ssh
- name: allow root ssh connections
lineinfile:
path: /etc/cloud/cloud.cfg
regexp: '^disable_root:'
line: 'disable_root: 0'
remote_user: fedora
become: true
become_user: root
when: birthday is defined
- name: use the same authorized_keys
replace:
path: /root/.ssh/authorized_keys
regexp: '.*Please login as the user.* ssh-rsa '
replace: 'ssh-rsa '
backup: yes
remote_user: fedora
become: true
become_user: root
when: birthday is defined
#
# Next we try and gather facts. If the host doesn't have python2 this will fail.
#
- name: gather facts
setup:
check_mode: no
ignore_errors: true
register: facts
#
# If that failed, then we use the raw module to install things
#
2020-02-19 22:35:10 +01:00
- name: install python3 and dnf stuff
raw: sudo dnf -y install python3-dnf python3-libselinux python3
when:
- birthday is defined
- facts is failed
# - name: Include SSH config
# import_role: name=basessh