main.yml 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. - name: system
  2. blockinfile:
  3. dest: /etc/ssh/ssh_config
  4. marker: '# ANSIBLE SSH CONFIG {mark}'
  5. block: |-
  6. {% for host in ssh_config_hosts %}
  7. {% set host_config = ssh_config_hosts[host] %}
  8. Host {{host}}
  9. {% if host_config.hostname is defined %}
  10. HostName {{host_config.hostname}}
  11. {% endif %}
  12. {% if host_config.user is defined %}
  13. User {{host_config.user}}
  14. {% endif %}
  15. {% if host_config.ssh_proxy is defined %}
  16. ProxyCommand ssh -W localhost:{{host_config.ssh_proxy.port}} {{host_config.ssh_proxy.host}}
  17. {% endif %}
  18. {% endfor %}
  19. become: yes
  20. - name: users
  21. blockinfile:
  22. dest: '~/.ssh/config'
  23. create: yes
  24. mode: 0600
  25. marker: '# ANSIBLE SSH CONFIG {mark}'
  26. block: |-
  27. {% set hosts = ssh_config_user_hosts[item] %}
  28. {% for host in hosts %}
  29. {% set host_config = hosts[host] %}
  30. Host {{host}}
  31. {% if host_config.hostname is defined %}
  32. HostName {{host_config.hostname}}
  33. {% endif %}
  34. {% if host_config.user is defined %}
  35. User {{host_config.user}}
  36. {% endif %}
  37. {% if host_config.ssh_proxy is defined %}
  38. ProxyCommand ssh -W localhost:{{host_config.ssh_proxy.port}} {{host_config.ssh_proxy.host}}
  39. {% endif %}
  40. {% endfor %}
  41. become: yes
  42. become_user: '{{item}}'
  43. with_items: '{{ssh_config_user_hosts}}'