Ansible: La opción "exclusiva" de allowed_keys falla con with_subelements

Creado en 3 jun. 2015  ·  3Comentarios  ·  Fuente: ansible/ansible

Cuando hago lo siguiente en ansible 1.9.1, trata cada clave _individual_ por usuario como exclusiva, no el _grupo_ de claves por usuario como exclusiva. Como resultado, solo se puede utilizar la última clave especificada por usuario.

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

Comentario más útil

He resuelto esto con un paso intermedio. Al igual que

# 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 comentarios

que se espera, está ejecutando el módulo X número de veces, cada vez con exclusivo (X == número de elementos).

Posible malentendido

¡Hola!

Muchas gracias por su envío a Ansible. Sinceramente, significa mucho para nosotros.

Creemos que la multa que ha presentado se está malinterpretando un poco, ya que una cosa funciona de manera un poco diferente a lo indicado.

En el futuro, este podría ser un tema más adecuado para la lista de usuarios, que también puede publicar aquí si desea obtener más ayuda con lo anterior.

¡Gracias una vez más por esto y su interés en Ansible!

He resuelto esto con un paso intermedio. Al igual que

# 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
¿Fue útil esta página
0 / 5 - 0 calificaciones