Ansible: Author_keys الخيار "الحصري" فشل ث / with_subelements

تم إنشاؤها على ٣ يونيو ٢٠١٥  ·  3تعليقات  ·  مصدر: 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 التقييمات