Ansible: authorized_keysの「exclusive」オプションがwith_subelementsで失敗する

作成日 2015年06月03日  ·  3コメント  ·  ソース: ansible/ansible

ansible 1.9.1で次のことを行うと、ユーザーごとのキーのグループではなく、ユーザーごとの各キーが排他的なものとして扱われます。 その結果、最後に指定されたユーザーごとのキーのみが使用可能になります。

- name: sync all users keys
  authorized_key: user={{item.0.name}} key='{{item.1}}' state=present exclusive=yes
  with_subelements:
    - users
    - keys

最も参考になるコメント

私はこれを中間ステップで解決しました。 そのようです

# 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

全てのコメント3件

つまり、モジュールを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
このページは役に立ちましたか?
0 / 5 - 0 評価