Feat: add ssh role
This commit is contained in:
parent
467ddc50e5
commit
d050172b77
38
roles/ssh/README.md
Normal file
38
roles/ssh/README.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Role Name
|
||||||
|
=========
|
||||||
|
|
||||||
|
A brief description of the role goes here.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
||||||
|
|
||||||
|
- hosts: servers
|
||||||
|
roles:
|
||||||
|
- { role: username.rolename, x: 42 }
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
BSD
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
|
4
roles/ssh/defaults/main.yml
Normal file
4
roles/ssh/defaults/main.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
# defaults file for ssh
|
||||||
|
sshd_configfilename: /etc/ssh/sshd_config
|
||||||
|
|
4
roles/ssh/handlers/main.yml
Normal file
4
roles/ssh/handlers/main.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
# handlers file for ssh
|
||||||
|
- name: restart sshd
|
||||||
|
service: name=ssh state=restarted
|
5
roles/ssh/tasks/debian.yml
Normal file
5
roles/ssh/tasks/debian.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Debian - Install ssh
|
||||||
|
apt:
|
||||||
|
name: openssh-server
|
||||||
|
state: present
|
35
roles/ssh/tasks/main.yml
Normal file
35
roles/ssh/tasks/main.yml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
---
|
||||||
|
# tasks file for core
|
||||||
|
- name: Install os-specific packages
|
||||||
|
include_tasks: "{{ ansible_os_family | lower }}.yml"
|
||||||
|
|
||||||
|
- name: Add identity key to authorized keys on host
|
||||||
|
authorized_key:
|
||||||
|
user: "{{ ssh_target_user }}"
|
||||||
|
key: "{{ ssh_publickey }}"
|
||||||
|
register: add_identity_key
|
||||||
|
when: ssh_target_user is defined and ssh_publickey is defined
|
||||||
|
|
||||||
|
- name: Disable empty password login
|
||||||
|
lineinfile:
|
||||||
|
dest: "{{ sshd_configfilename }}"
|
||||||
|
regexp: '^#?PermitEmptyPasswords'
|
||||||
|
line: 'PermitEmptyPasswords no'
|
||||||
|
notify: restart sshd
|
||||||
|
|
||||||
|
- name: Disable remote root login
|
||||||
|
lineinfile:
|
||||||
|
dest: "{{ sshd_configfilename }}"
|
||||||
|
regexp: '^#?PermitRootLogin'
|
||||||
|
line: 'PermitRootLogin no'
|
||||||
|
notify: restart sshd
|
||||||
|
|
||||||
|
- name: Disable password login
|
||||||
|
lineinfile:
|
||||||
|
dest: "{{ sshd_configfilename }}"
|
||||||
|
regexp: '^(#\s*)?PasswordAuthentication '
|
||||||
|
line: 'PasswordAuthentication no'
|
||||||
|
when:
|
||||||
|
- add_identity_key is succeeded
|
||||||
|
- not add_identity_key is skipped
|
||||||
|
notify: restart sshd
|
2
roles/ssh/vars/main.yml
Normal file
2
roles/ssh/vars/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# vars file for ssh
|
Loading…
Reference in New Issue
Block a user