瀏覽代碼

known hosts handling via template

master
父節點
當前提交
a3f973111c
共有 2 個文件被更改,包括 7 次插入3 次删除
  1. +2
    -2
      tasks/file.yml
  2. +5
    -1
      templates/ssh_host_key.j2

+ 2
- 2
tasks/file.yml 查看文件

@@ -1,10 +1,10 @@
---
- name: write ssh_known_hosts file
local_action: known_hosts
args:
path: "{{ playbook_dir }}/ssh_known_hosts"
name: "{{ item }}"
key: "{{ item }},{{ hostvars[item].ssh_ip }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }}"
key: "{{ lookup('template','ssh_host_key.j2') }}"
with_items: "{{play_hosts}}"
run_once: true

+ 5
- 1
templates/ssh_host_key.j2 查看文件

@@ -1 +1,5 @@
{{ _ssh_key_type[ssh_host_key_type] }} {% if ssh_host_key_type == "ed25519" %}{{ ssh_host_key_ed25519_public }}{% endif %}
{% if hostvars[item].ssh_ip is defined %}
{{ item }},{{ hostvars[item].ssh_ip }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }}
{% else %}
{{ item }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }}
{% endif %}

Loading…
取消
儲存