Ansible_workstation/tasks/ssh.yml

61 lines
1.4 KiB
YAML
Raw Normal View History

2018-08-24 08:00:59 +00:00
---
# - name: Copy sshd_config
# template:
# src: files/sshd_config
# dest: /etc/ssh/sshd_config
2018-08-24 09:00:52 +00:00
- name: Disable empty password login
lineinfile:
dest: /etc/ssh/sshd_config
regexp: "^#?PermitEmptyPasswords"
line: "PermitEmptyPasswords no"
backrefs: yes
2018-11-07 09:57:55 +00:00
tags:
- first_deployement
2018-08-24 09:00:52 +00:00
- name: Disable remote root login
lineinfile:
dest: /etc/ssh/sshd_config
regexp: "^#?PermitRootLogin"
line: "PermitRootLogin no"
backrefs: yes
2018-11-07 09:57:55 +00:00
tags:
- first_deployement
2018-08-24 09:00:52 +00:00
- name: Add public key for deploy user
authorized_key:
2018-08-24 08:59:13 +00:00
user: "{{ item.username }}"
key: "{{ lookup('file', 'sshpubs/' + deploy_public_key) }}"
2018-08-24 09:14:48 +00:00
state: present
2018-08-24 08:59:13 +00:00
with_items: "{{ deploy_users }}"
2018-08-24 09:00:52 +00:00
register: add_identity_key
2018-11-07 09:57:55 +00:00
tags:
- first_deployement
2018-08-24 09:00:52 +00:00
- name: Disable password login
lineinfile:
dest: /etc/ssh/sshd_config
regexp: "^#?PasswordAuthentication"
line: "PasswordAuthentication no"
backrefs: yes
2018-08-25 13:15:17 +00:00
when: add_identity_key is succeeded and not add_identity_key is skipped
2018-08-24 08:13:15 +00:00
notify: restart sshd
2018-11-07 09:57:55 +00:00
tags:
- first_deployement
2018-08-24 08:13:15 +00:00
2019-02-06 19:18:37 +00:00
- name: Enable SSH daemon (not Debian)
2018-08-24 08:13:15 +00:00
service:
name: sshd
state: started
enabled: yes
2018-11-07 09:57:55 +00:00
tags:
- first_deployement
2019-02-06 19:18:37 +00:00
when: ansible_distribution != 'Debian'
2018-08-24 08:17:21 +00:00
2019-02-06 19:18:37 +00:00
- name: Enable SSH daemon (Debian)
service:
name: ssh
state: started
enabled: yes
when: ansible_distribution == 'Debian'