Skip to content

Instantly share code, notes, and snippets.

@noblejasper
Created April 28, 2015 12:40
Show Gist options
  • Save noblejasper/a7ee36ae9a24628ec3c4 to your computer and use it in GitHub Desktop.
Save noblejasper/a7ee36ae9a24628ec3c4 to your computer and use it in GitHub Desktop.
[調査中] Ansible で何人かのユーザーをroot@でもログイン出来るようにしたい
# TODO: ルートユーザーにauthorized_keysを足すのが上手くいってない
# root_usersには該当するユーザー名のリストが入っている
# 各ユーザーのauthorized_keysを持ってきて root に足したい
# 各ユーザーのkeysが複数行だった場合にどんどん行数が増えてしまう
# そして冪等性が保たれない。つらい
- name: read root user's authorized_keys
shell: cat /home/{{item}}/.ssh/authorized_keys
with_items: root_users
register: output_keys
- name: write root keys that readed keys
lineinfile:
dest: /root/.ssh/authorized_keys
line: "{{ item.stdout }}"
regexp: "^.*{{ item.stdout[-10:] }}$"
create: yes
state: present
with_items: output_keys.results
@noblejasper
Copy link
Author

結論

実際のコード

- name: regist root key
  authorized_key: >
    user=root
    key="{{ lookup('file', item ~ '_authorized_keys') }}"
    path='/root/.ssh/authorized_keys'
    manage_dir=no
  with_items: root_users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment