1.9.1์์ ๋ค์์ ์ํํ๋ฉด ์ฌ์ฉ์๋ณ ํค์ _group_์ด ๋จ๋ ์ผ๋ก ์ฒ๋ฆฌ๋์ง ์๊ณ ๊ฐ _individual_ ์ฌ์ฉ์๋ณ ํค๊ฐ ๋จ๋ ์ผ๋ก ์ฒ๋ฆฌ๋ฉ๋๋ค. ๊ฒฐ๊ณผ์ ์ผ๋ก ๋ง์ง๋ง์ผ๋ก ์ง์ ๋ ์ฌ์ฉ์๋ณ ํค๋ง ์ฌ์ฉํ ์ ์์ต๋๋ค.
- name: sync all users keys
authorized_key: user={{item.0.name}} key='{{item.1}}' state=present exclusive=yes
with_subelements:
- users
- keys
์ฆ, ๋งค๋ฒ ๋ฐฐํ์ (X == ํญ๋ชฉ ์)์ผ๋ก ๋ชจ๋์ X๋ฒ ์คํํ๊ณ ์์ต๋๋ค.
์๋ ํ์ธ์!
Ansible์ ์ ์ถํด ์ฃผ์ ์ ๋๋จํ ๊ฐ์ฌํฉ๋๋ค. ๊ทธ๊ฒ์ ์ง์ฌ์ผ๋ก ์ฐ๋ฆฌ์๊ฒ ๋ง์ ๊ฒ์ ์๋ฏธํฉ๋๋ค.
ํ ๊ฐ์ง๊ฐ ๋ช ์๋ ๊ฒ๊ณผ ์กฐ๊ธ ๋ค๋ฅด๊ฒ ์๋ํ๊ธฐ ๋๋ฌธ์ ๊ทํ๊ฐ ์ ์ถํ ํฐ์ผ์ด ๋ค์ ์คํด๋๊ณ ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
์์ผ๋ก ์ด๊ฒ์ ์ฌ์ฉ์ ๋ชฉ๋ก์ ๋ ์ ํฉํ ์ฃผ์ ๊ฐ ๋ ์ ์์ผ๋ฉฐ ์์ ๋ด์ฉ๊ณผ ๊ด๋ จํ์ฌ ๋ ๋ง์ ๋์์ด ํ์ํ ๊ฒฝ์ฐ ์ฌ๊ธฐ์ ๊ฒ์ํ ์๋ ์์ต๋๋ค.
๋ค์ ํ๋ฒ Ansible์ ๋ํ ๊ด์ฌ๊ณผ ์ฑ์์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค!
๋๋ ์ด๊ฒ์ ์ค๊ฐ ๋จ๊ณ๋ก ํด๊ฒฐํ์ต๋๋ค. ๊ทธ๋ ๊ฒ
# Read each file and split by newline, allowing for multiple keys per file
- name: Assemble keys
set_fact:
key_item: "{{ lookup('file', role_path + '/files/' + item).split('\n') }}"
with_items:
- bob.pub
- fred.pub
- barney.pub
register: keys
# Select each key, joining it again and join all keys. Internally the ansible
# module will then split the string by newline and work at each one. This is
# the only way exclusive works with a list of keys.
- name: Distribute operations ssh-keys to root
authorized_key:
key : "{{ keys.results|selectattr('ansible_facts','defined')|map(attribute='ansible_facts.key_item')|map('join', '\n')|join('\n') }}"
manage_dir : yes
state : present
user : root
exclusive : yes
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ ์ด๊ฒ์ ์ค๊ฐ ๋จ๊ณ๋ก ํด๊ฒฐํ์ต๋๋ค. ๊ทธ๋ ๊ฒ