Browse Source

added user config

Fabian Peter Hammerle 7 years ago
parent
commit
694290b3ee
2 changed files with 27 additions and 1 deletions
  1. 1 0
      defaults/main.yml
  2. 26 1
      tasks/main.yml

+ 1 - 0
defaults/main.yml

@@ -1 +1,2 @@
 ssh_config_hosts: []
+ssh_config_user_hosts: []

+ 26 - 1
tasks/main.yml

@@ -1,4 +1,5 @@
-- blockinfile:
+- name: system
+  blockinfile:
     dest: /etc/ssh/ssh_config
     marker: '# ANSIBLE SSH CONFIG {mark}'
     block: |-
@@ -16,3 +17,27 @@
       {% endif %}
       {% endfor %}
   become: yes
+- name: users
+  blockinfile:
+    dest: '~/.ssh/config'
+    create: yes
+    mode: 0600
+    marker: '# ANSIBLE SSH CONFIG {mark}'
+    block: |-
+      {% set hosts = ssh_config_user_hosts[item] %}
+      {% for host in hosts %}
+      {% set host_config = hosts[host] %}
+      Host {{host}}
+      {% if host_config.hostname is defined %}
+          HostName {{host_config.hostname}}
+      {% endif %}
+      {% if host_config.user is defined %}
+          User {{host_config.user}}
+      {% endif %}
+      {% if host_config.ssh_proxy is defined %}
+          ProxyCommand ssh -W localhost:{{host_config.ssh_proxy.port}} {{host_config.ssh_proxy.host}}
+      {% endif %}
+      {% endfor %}
+  become: yes
+  become_user: '{{item}}'
+  with_items: '{{ssh_config_user_hosts}}'