Ansible: Die "exklusive" Option "authorized_keys" schlägt mit with_subelements fehl

Erstellt am 3. Juni 2015  ·  3Kommentare  ·  Quelle: ansible/ansible

Wenn ich in ansible 1.9.1 Folgendes mache, behandelt es jeden _individuellen_ pro-Benutzer-Schlüssel als exklusiv, nicht die _Gruppe_ von pro-Benutzer-Schlüsseln als exklusiv. Dadurch ist nur der zuletzt angegebene benutzerspezifische Schlüssel verwendbar.

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

Hilfreichster Kommentar

Ich habe das durch einen Zwischenschritt gelöst. Gefällt mir

# 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

Alle 3 Kommentare

das wird erwartet, Sie führen das Modul X-mal aus, jedes Mal mit exklusiv (X == Anzahl der Elemente).

Mögliches Missverständnis

Hi!

Vielen Dank für Ihre Übermittlung an Ansible. Es bedeutet uns aufrichtig viel.

Wir glauben, dass das von Ihnen eingereichte Ticket etwas missverstanden wird, da eine Sache etwas anders funktioniert als angegeben.

In Zukunft könnte dies ein Thema sein, das besser für die Benutzerliste geeignet ist, das Sie auch hier posten können, wenn Sie mehr Hilfe zu den oben genannten Punkten benötigen.

Nochmals vielen Dank dafür und Ihr Interesse an Ansible!

Ich habe das durch einen Zwischenschritt gelöst. Gefällt mir

# 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
War diese Seite hilfreich?
0 / 5 - 0 Bewertungen