---
# 恢復 SSH 密碼驗證 — 統帥授權 2026-05-04
# 執行: ansible-playbook -i inventory/hosts.yml playbooks/restore-password-auth.yml --extra-vars @/tmp/awoooi-pw.yml
# 完成後刪除 /tmp/awoooi-pw.yml

- name: "四台主機恢復 SSH 密碼驗證"
  hosts: host_110,host_120,host_121,host_188
  become: true
  vars:
    ansible_become_pass: "{{ user_password }}"

  tasks:
    - name: "SSH | 啟用 PasswordAuthentication"
      ansible.builtin.lineinfile:
        path: /etc/ssh/sshd_config
        regexp: '^#?PasswordAuthentication'
        line: 'PasswordAuthentication yes'
        state: present
      notify: reload sshd

    - name: "SSH | 設定系統使用者密碼"
      ansible.builtin.user:
        name: "{{ ansible_user }}"
        password: "{{ user_password | password_hash('sha512') }}"
      no_log: true

  handlers:
    - name: reload sshd
      ansible.builtin.systemd:
        name: ssh
        state: reloaded
