Formatting plus notify in sshd; allow username instead of only name in

variables; use which instead of command
- Formatting + notify in sshd config
- Use which instead of command (because of problems with sudo [no such file or directory])
- Allow using username instead of name in variables (because of compliance with oh-my-zsh role (https://github.com/gantsign/ansible-role-oh-my-zsh))
main
Leo Maroni 5 years ago committed by Leo Maroni
parent 3438e661a3
commit 884710fb1f

@ -0,0 +1,5 @@
---
- name: reload sshd service
systemd:
name: sshd.service
state: reloaded

@ -4,11 +4,11 @@
path: /etc/ssh/sshd_config path: /etc/ssh/sshd_config
regexp: '^#?AuthenticationMethods ' regexp: '^#?AuthenticationMethods '
line: 'AuthenticationMethods publickey' line: 'AuthenticationMethods publickey'
service: name=sshd state=restarted notify: reload sshd service
- name: Disable SSH password authentication - name: Disable SSH password authentication
lineinfile: lineinfile:
path: /etc/ssh/sshd_config path: /etc/ssh/sshd_config
regexp: '^#?PasswordAuthentication ' regexp: '^#?PasswordAuthentication '
line: 'PasswordAuthentication no' line: 'PasswordAuthentication no'
service: name=sshd state=restarted notify: reload sshd service

@ -8,21 +8,21 @@
- "{{ users }}" - "{{ users }}"
- name: get bash's path - name: get bash's path
command: command -v bash command: which bash
register: bash_path register: bash_path
changed_when: false changed_when: false
- name: create user - name: create user
user: state=present user: state=present
name="{{ item.name }}" name="{{ item.username if item.username is defined else item.name }}"
groups="sudo,adm" append=yes groups="{{ "sudo,adm" if item.sudo is defined and item.sudo }}" append=yes
shell={{ item.shell | default(bash_path.stdout) }} shell={{ item.shell | default(bash_path.stdout) }}
with_items: with_items:
- "{{ users }}" - "{{ users }}"
when: item.state != 'absent' when: item.state != 'absent'
- name: add user's authorized_keys - name: add user's authorized_keys
authorized_key: user="{{ item.name }}" manage_dir=true key="{{ item.public_key }}" authorized_key: user="{{ item.username if item.username is defined else item.name }}" manage_dir=true key="{{ item.public_key }}"
state=present exclusive=yes state=present exclusive=yes
with_items: with_items:
- "{{ users }}" - "{{ users }}"
@ -55,7 +55,7 @@
- name: create pve user - name: create pve user
command: command:
cmd: 'pveum useradd {{ item.name }}@pam' cmd: 'pveum useradd {{ item.username if item.username is defined else item.name }}@pam'
with_items: with_items:
- "{{ users }}" - "{{ users }}"
when: item.state != 'absent' and 'proxmox' in group_names when: item.state != 'absent' and 'proxmox' in group_names
@ -63,7 +63,7 @@
- name: disable pve user - name: disable pve user
command: command:
cmd: 'pveum usermod {{ item.name }}@pam -enable 0' cmd: 'pveum usermod {{ item.username if item.username is defined else item.name }}@pam -enable 0'
with_items: with_items:
- "{{ users }}" - "{{ users }}"
when: item.state == 'absent' and 'proxmox' in group_names when: item.state == 'absent' and 'proxmox' in group_names
@ -71,7 +71,7 @@
- name: add user to pve admin group - name: add user to pve admin group
command: command:
cmd: 'pveum usermod {{ item.name }}@pam -group admin' cmd: 'pveum usermod {{ item.username if item.username is defined else item.name }}@pam -group admin'
with_items: with_items:
- "{{ users }}" - "{{ users }}"
when: item.state != 'absent' and 'proxmox' in group_names when: item.state != 'absent' and 'proxmox' in group_names

Loading…
Cancel
Save