begin using galaxy
This commit is contained in:
@@ -1,13 +1,35 @@
|
||||
---
|
||||
# https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html#examples
|
||||
- name: update apt-cache and upgrade
|
||||
- name: update ssh key and login permissions
|
||||
strategy: free # dont wait for other hosts when executing
|
||||
hosts: oracleServer
|
||||
tasks:
|
||||
- name: upgrade packages
|
||||
|
||||
- name: Add ssh key
|
||||
become: true
|
||||
async: 120 # Maximum execution time
|
||||
poll: 05 # polling interval in seconds
|
||||
ansible.posix.authorized_key:
|
||||
user: "{{ ansible_user_id }}"
|
||||
exclusive: true
|
||||
state: present
|
||||
key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}"
|
||||
|
||||
- name: sshd configuration file update
|
||||
blockinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
insertbefore: BOF # Beginning of the file
|
||||
marker: "# {mark} ANSIBLE MANAGED BLOCK BY LINUX-ADMIN"
|
||||
block: |
|
||||
PermitRootLogin no
|
||||
PubkeyAuthentication yes
|
||||
AuthorizedKeysFile .ssh/authorized_keys
|
||||
PasswordAuthentication no
|
||||
backup: true
|
||||
validate: /usr/sbin/sshd -T -f %s
|
||||
|
||||
- name: Restart SSHD
|
||||
service:
|
||||
name: sshd
|
||||
state: restarted
|
||||
|
||||
|
||||
Reference in New Issue
Block a user