feat(ansible): ansible 初步稳定
这个提交包含在:
+10
-28
@@ -5,7 +5,7 @@
|
||||
ansible.builtin.file:
|
||||
path: /root/.ssh
|
||||
state: directory
|
||||
mode: '0700'
|
||||
mode: "0700"
|
||||
|
||||
- name: Add SSH public key
|
||||
ansible.builtin.authorized_key:
|
||||
@@ -17,35 +17,17 @@
|
||||
ansible.builtin.copy:
|
||||
src: /etc/ssh/sshd_config
|
||||
dest: /etc/ssh/sshd_config.bak
|
||||
remote_src: yes
|
||||
force: no
|
||||
remote_src: true
|
||||
force: false
|
||||
mode: "0600"
|
||||
|
||||
- name: Deploy secure sshd_config
|
||||
ansible.builtin.template:
|
||||
src: sshd_config.j2
|
||||
dest: /etc/ssh/sshd_config
|
||||
mode: '0600'
|
||||
validate: '/usr/sbin/sshd -t -f %s'
|
||||
register: sshd_config
|
||||
|
||||
- name: Restart sshd service
|
||||
ansible.builtin.systemd:
|
||||
name: sshd
|
||||
state: restarted
|
||||
when: sshd_config.changed
|
||||
|
||||
- name: Update ansible_port to new SSH port
|
||||
ansible.builtin.set_fact:
|
||||
ansible_port: "{{ ssh_new_port }}"
|
||||
when: sshd_config.changed
|
||||
|
||||
- name: Wait for SSH on new port
|
||||
ansible.builtin.wait_for:
|
||||
port: "{{ ssh_new_port }}"
|
||||
host: "{{ ansible_host }}"
|
||||
delay: 5
|
||||
timeout: 60
|
||||
delegate_to: localhost
|
||||
become: no
|
||||
when: sshd_config.changed
|
||||
|
||||
mode: "0600"
|
||||
validate: "/usr/sbin/sshd -t -f %s"
|
||||
notify:
|
||||
- Restart sshd
|
||||
- Update ansible port
|
||||
- Wait for new SSH port
|
||||
|
||||
在新议题中引用
屏蔽一个用户