If authorized_key doesn't work, try lineinfile (Python interpreter problem)
This commit is contained in:
parent
4d95c09591
commit
dbf35931c2
|
@ -140,10 +140,30 @@
|
||||||
|
|
||||||
|
|
||||||
- name: Add SSH keys
|
- name: Add SSH keys
|
||||||
authorized_key:
|
block:
|
||||||
user: root
|
- name: "1st try: authorized_key module"
|
||||||
key: "{{ item }}"
|
authorized_key:
|
||||||
loop: "{{ ssh_keys }}"
|
user: root
|
||||||
|
key: "{{ item }}"
|
||||||
|
loop: "{{ ssh_keys }}"
|
||||||
|
rescue:
|
||||||
|
- name: "2nd try: create ~/.ssh directory"
|
||||||
|
file:
|
||||||
|
path: /root/.ssh/
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0700
|
||||||
|
- name: "2nd try: add key via lineinfile module"
|
||||||
|
lineinfile:
|
||||||
|
path: /root/.ssh/authorized_keys
|
||||||
|
line: "{{ item }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0600
|
||||||
|
create: yes
|
||||||
|
backup: yes
|
||||||
|
loop: "{{ ssh_keys }}"
|
||||||
|
|
||||||
|
|
||||||
- name: "[BLOCK] when 'service_username' is set"
|
- name: "[BLOCK] when 'service_username' is set"
|
||||||
|
@ -161,10 +181,36 @@
|
||||||
|
|
||||||
|
|
||||||
- name: Add SSH keys
|
- name: Add SSH keys
|
||||||
authorized_key:
|
block:
|
||||||
user: "{{ service_username }}"
|
- name: "1st try: authorized_key module"
|
||||||
key: "{{ item }}"
|
authorized_key:
|
||||||
loop: "{{ ssh_keys_service|default(ssh_keys) }}"
|
user: "{{ service_username }}"
|
||||||
|
key: "{{ item }}"
|
||||||
|
loop: "{{ ssh_keys_service|default(ssh_keys) }}"
|
||||||
|
rescue:
|
||||||
|
- name: "2nd try: get homedir of user"
|
||||||
|
getent:
|
||||||
|
database: passwd
|
||||||
|
key: "{{ service_username }}"
|
||||||
|
split: ":"
|
||||||
|
- name: "2nd try: create ~/.ssh directory"
|
||||||
|
file:
|
||||||
|
path: "{{ getent_passwd[service_username][4] }}/.ssh/"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ service_username }}"
|
||||||
|
group: "{{ service_username }}"
|
||||||
|
mode: 0700
|
||||||
|
- name: "2nd try: add key via lineinfile module"
|
||||||
|
lineinfile:
|
||||||
|
path: "{{ getent_passwd[service_username][4] }}/.ssh/authorized_keys"
|
||||||
|
line: "{{ item }}"
|
||||||
|
owner: "{{ service_username }}"
|
||||||
|
group: "{{ service_username }}"
|
||||||
|
mode: 0600
|
||||||
|
create: yes
|
||||||
|
backup: yes
|
||||||
|
loop: "{{ ssh_keys }}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- name: Install sudo
|
- name: Install sudo
|
||||||
|
|
Loading…
Reference in a new issue