2022-12-10 17:51:03 +00:00
|
|
|
- name: Ensure SSH instalation
|
2022-10-23 13:28:33 +00:00
|
|
|
become: true
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.builtin.package:
|
|
|
|
name: '{{ system_ssh_package }}'
|
2022-10-23 13:28:33 +00:00
|
|
|
state: present
|
2022-12-10 17:51:03 +00:00
|
|
|
- name: Ensure .ssh exist for user
|
2022-11-06 18:10:26 +00:00
|
|
|
become: true
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.builtin.file:
|
2022-11-06 18:10:26 +00:00
|
|
|
state: directory
|
2022-12-10 17:51:03 +00:00
|
|
|
path: '/home/{{ item }}/.ssh'
|
|
|
|
owner: '{{ item }}'
|
2022-11-06 18:10:26 +00:00
|
|
|
mode: 0700
|
|
|
|
with_items:
|
2022-12-10 17:51:03 +00:00
|
|
|
- '{{ user.name }}'
|
2022-11-11 16:49:55 +00:00
|
|
|
- ansible
|
2022-11-06 18:10:26 +00:00
|
|
|
|
2022-12-10 17:51:03 +00:00
|
|
|
- name: Copy ssh config for user
|
2022-02-13 08:40:15 +00:00
|
|
|
become: true
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.builtin.template:
|
|
|
|
dest: '/home/{{ item }}/.ssh/config'
|
|
|
|
src: 'ssh/config.j2'
|
2022-02-13 08:40:15 +00:00
|
|
|
force: true
|
|
|
|
remote_src: false
|
2022-12-10 17:51:03 +00:00
|
|
|
mode: '600'
|
2022-02-13 08:40:15 +00:00
|
|
|
selevel: s0
|
2022-12-10 17:51:03 +00:00
|
|
|
owner: '{{ item }}'
|
2020-03-01 20:06:02 +00:00
|
|
|
with_items:
|
2022-12-10 17:51:03 +00:00
|
|
|
- '{{ user.name }}'
|
2022-11-11 16:49:55 +00:00
|
|
|
- ansible
|
2022-12-10 17:51:03 +00:00
|
|
|
- name: Ensure root ssh directory exist
|
2021-07-10 12:41:35 +00:00
|
|
|
become: true
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.builtin.file:
|
2021-07-10 12:41:35 +00:00
|
|
|
state: directory
|
2022-12-10 17:51:03 +00:00
|
|
|
path: '/root/.ssh'
|
|
|
|
owner: 'root'
|
2021-07-10 12:41:35 +00:00
|
|
|
mode: 0700
|
|
|
|
|
2022-12-10 17:51:03 +00:00
|
|
|
- name: Copy ssh config for root
|
2022-02-13 08:40:15 +00:00
|
|
|
become: true
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.builtin.copy:
|
2022-02-13 08:40:15 +00:00
|
|
|
dest: /root/.ssh/
|
2022-12-10 17:51:03 +00:00
|
|
|
src: 'ssh/config'
|
2022-02-13 08:40:15 +00:00
|
|
|
force: true
|
|
|
|
remote_src: false
|
2022-12-10 17:51:03 +00:00
|
|
|
mode: '600'
|
2022-02-13 08:40:15 +00:00
|
|
|
selevel: s0
|
2022-12-10 17:51:03 +00:00
|
|
|
owner: 'root'
|
2021-07-10 12:41:35 +00:00
|
|
|
|
2022-12-10 17:51:03 +00:00
|
|
|
- name: Ensure key directory exist
|
2021-07-10 12:40:17 +00:00
|
|
|
become: true
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.builtin.file:
|
2021-07-10 12:40:17 +00:00
|
|
|
state: directory
|
2022-12-10 17:51:03 +00:00
|
|
|
path: '{{ item.keyfile | dirname }}'
|
|
|
|
owner: '{{ item.user }}'
|
2021-07-10 12:41:35 +00:00
|
|
|
mode: 0700
|
2022-12-10 17:51:03 +00:00
|
|
|
with_items: '{{ privatekeytodeploy }}'
|
2020-03-01 20:06:02 +00:00
|
|
|
|
2021-04-20 08:18:56 +00:00
|
|
|
- name: Install ssh private key
|
2022-02-13 08:40:15 +00:00
|
|
|
become: true
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.builtin.copy:
|
|
|
|
content: '{{ item.privatekey }}'
|
|
|
|
dest: '{{ item.keyfile }}'
|
2021-04-20 08:18:56 +00:00
|
|
|
mode: 0600
|
2022-12-10 17:51:03 +00:00
|
|
|
owner: '{{ item.user }}'
|
|
|
|
with_items: '{{ privatekeytodeploy }}'
|
2020-03-01 20:06:02 +00:00
|
|
|
|
|
|
|
- name: Deploy SSH-Keys to remote host
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.posix.authorized_key:
|
|
|
|
user: '{{ item.user }}'
|
|
|
|
key: '{{ item.sshkey }}'
|
2022-02-13 08:40:15 +00:00
|
|
|
exclusive: false
|
2022-12-10 17:51:03 +00:00
|
|
|
with_items: '{{ keystodeploy }}'
|
2022-02-13 08:40:15 +00:00
|
|
|
become: true
|
2020-03-02 20:19:09 +00:00
|
|
|
|
2022-12-10 17:51:03 +00:00
|
|
|
- name: Les connexions par mot de passe sont désactivées
|
2022-02-13 08:40:15 +00:00
|
|
|
become: true
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.builtin.lineinfile:
|
2021-07-10 12:40:17 +00:00
|
|
|
dest: /etc/ssh/sshd_config
|
2022-12-10 17:51:03 +00:00
|
|
|
regexp: '^#?PasswordAuthentication'
|
|
|
|
line: 'PasswordAuthentication no'
|
2020-03-02 20:19:09 +00:00
|
|
|
state: present
|
|
|
|
notify: Restart sshd
|
|
|
|
|
|
|
|
- name: Remove root SSH access
|
2022-02-13 08:40:15 +00:00
|
|
|
become: true
|
2022-12-10 17:51:03 +00:00
|
|
|
ansible.builtin.lineinfile:
|
2021-07-10 12:40:17 +00:00
|
|
|
dest: /etc/ssh/sshd_config
|
2022-12-10 17:51:03 +00:00
|
|
|
regexp: '^PermitRootLogin'
|
|
|
|
line: 'PermitRootLogin no'
|
2020-03-02 20:19:09 +00:00
|
|
|
state: present
|
|
|
|
notify: Restart sshd
|