---
- name: 设置Nomad节点SSH密钥认证
  hosts: nomad_nodes
  become: yes
  vars:
    ssh_public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIIddJVPEvFRtzhWwYjr21lKTar+d7R5Kn/6bhd2s231 ben@ch2"

  tasks:
    - name: 确保.ssh目录存在
      file:
        path: /root/.ssh
        state: directory
        mode: '0700'

    - name: 添加SSH公钥到authorized_keys
      authorized_key:
        user: root
        state: present
        key: "{{ ssh_public_key }}"

    - name: 测试SSH连接
      ping: