You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

3 年之前
3 年之前
3 年之前
123456789101112131415161718192021222324252627282930313233343536
  1. ---
  2. - hosts:
  3. - servers
  4. - desktops
  5. - laptops
  6. remote_user: root
  7. roles:
  8. - name: users
  9. - hosts: desktops:laptops
  10. remote_user: root
  11. tasks:
  12. - name: /etc/ssh/ssh_config
  13. template:
  14. src: ssh_config.j2
  15. dest: /etc/ssh/ssh_config
  16. - name: ssh known hosts
  17. known_hosts:
  18. name: "{{item}}"
  19. key: "{{item}},{{hostvars[item].ansible_all_ipv4_addresses|join(',')}},{{hostvars[item].ansible_all_ipv6_addresses|join(',')}} {{hostvars[item].ansible_ssh_host_key_ed25519_public_keytype}} {{hostvars[item].ansible_ssh_host_key_ed25519_public}}"
  20. path: /etc/ssh/ssh_known_hosts
  21. loop: "{{groups.servers}}"
  22. - hosts:
  23. - servers
  24. remote_user: root
  25. tasks:
  26. - name: authorize ssh public keys
  27. authorized_key:
  28. user: "{{item.name}}"
  29. key: "{{item.ssh_public_key}}"
  30. loop: "{{ hostvars | json_query(\"*.user_ssh_keys_info.results[]\") }}"
  31. loop_control:
  32. label: "{{ item.name }}"