MUXX:
si je v inventory zarad do skupin a pro kazdej prislusnej host... neco ve stylu:
- name: Set authorized key for DEV
authorized_key:
state: present
key: "{{ lookup('file', 'keys/dev_id_rsa.pub') }}"
when: inventory_hostname in groups['dev']
- name: Set authorized key for QA
authorized_key:
state: present
key: "{{ lookup('file', 'keys/qa_id_rsa.pub') }}"
when: inventory_hostname in groups['qa']
Anebo si treba v group_vars/all.yml nadefinuj slovnik klicu:
ssh_keys:
dev: 'keys/dev_id_rsa.pub'
qa: 'keys/qa_id_rsa.pub'
a ten play zavolas jen jednou a vytahnes si prislusnej klic dle skupiny:
- name: Get path for key
set_fact:
key_path: "{{ ssh_keys[group_names[0]] }}"
- name: Set authorized key
authorized_key:
state: present
key: "{{ lookup('file', keys_path) }}"
(tohle bude ale fungovat v pripade pouze jedny skupiny)