Ansible: A opção "exclusive" de authorized_keys falha c / com_subelementos

Criado em 3 jun. 2015  ·  3Comentários  ·  Fonte: ansible/ansible

Quando eu faço o seguinte no ansible 1.9.1, ele trata cada chave _individual_ por usuário como exclusiva, não o _grupo_ de chaves por usuário como exclusiva. Como resultado, apenas a última chave especificada por usuário pode ser usada.

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

Comentários muito úteis

Resolvi isso em uma etapa intermediária. Igual a

# 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

Todos 3 comentários

o que é esperado, você está executando o módulo X número de vezes, cada vez com exclusivo (X == número de itens).

Possível mal-entendido

Oi!

Muito obrigado por seu envio para a Ansible. Sinceramente, significa muito para nós.

Acreditamos que o tíquete que você preencheu está sendo mal interpretado, pois uma coisa funciona de maneira um pouco diferente do que foi declarado.

No futuro, este pode ser um tópico mais adequado para a lista de usuários, que você também pode postar aqui se desejar mais ajuda com o acima.

Obrigado mais uma vez por isso e pelo seu interesse na Ansible!

Resolvi isso em uma etapa intermediária. Igual a

# 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
Esta página foi útil?
0 / 5 - 0 avaliações