Ansible內(nèi)置模塊之known_hosts
發(fā)布作者:微思網(wǎng)絡(luò) 發(fā)布時間:2024-11-12 瀏覽量:0次
選項 必須 類型 默認(rèn)值 說明 url 是 str 無 要下載文件的 URL dest 是 str 無 目標(biāo)文件路徑 mode 否 str 無 目標(biāo)文件的權(quán)限,如 0644、0755 等 owner 否 str 無 目標(biāo)文件的所有者 group 否 str 無 目標(biāo)文件的屬組 checksum 否 str no 用于驗證下載文件的 SHA256 校驗和 force 否 bool 無 如果目標(biāo)文件存在,是否強制覆蓋 timeout 否 int no 設(shè)置下載的超時時間(秒) headers 否 list 無 用于下載請求的 HTTP 頭 url_password 否 str 無 用于下載請求的密碼 url_username 否 str 無 用于下載請求的用戶名 validate_certs 否 bool yes 如果為 no,忽略 SSL 證書驗證錯誤 use_proxy 否 bool yes 是否使用系統(tǒng)中定義的代理 client_cert 否 str 無 用于下載請求的客戶端證書文件路徑 client_key 否 str 無 用于下載請求的客戶端密鑰文件路徑 http_agent 否 str ansible-httpget 設(shè)置下載請求的 HTTP User-Agent 頭
# 利用文件向 known_hosts 文件添加主機公鑰
- name: Tell the host about our servers it might want to ssh to
ansible.builtin.known_hosts:
path: /etc/ssh/ssh_known_hosts
name: foo.com.invalid
key: "{{ lookup('ansible.builtin.file', 'pubkeys/foo.com.invalid') }}"
# 向 known_hosts 文件添加主機公鑰
- name: Another way to call known_hosts
ansible.builtin.known_hosts:
name: host1.example.com # or 10.9.8.77
key: host1.example.com,10.9.8.77 ssh-rsa ASDeararAIUHI324324
path: /etc/ssh/ssh_known_hosts
state: present
# 向 known_hosts 文件添加特定ssh端口的主機公鑰
- name: Add host with custom SSH port
ansible.builtin.known_hosts:
name: '[host1.example.com]:2222'
key: '[host1.example.com]:2222 ssh-rsa ASDeararAIUHI324324'
path: /etc/ssh/ssh_known_hosts
state: present
# 向 known_hosts 文件添加多個主機公鑰
- name: Add multiple host keys to known_hosts
ansible.builtin.known_hosts:
path: /home/user/.ssh/known_hosts
host: "{{ item.host }}"
key: "{{ item.key }}"
state: present
loop:
- { host: "git.example.com", key: "ssh-rsa AAAAB3NzaC1yAQEYb... user@host" }
- { host: "hg.example.com", key: "ssh-rsa AAAAB3NzaC1ycAAr5zYb... user@host" }
# 向默認(rèn)的 known_hosts 文件添加主機公鑰并哈希化主機名
- name: Add a host key to known_hosts with hashed hostnames
ansible.builtin.known_hosts:
host: git.example.com
key: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAr5zYb... user@host
hash_host: yes
# 從 known_hosts 文件中刪除主機公鑰
- name: Remove a host key from known_hosts
ansible.builtin.known_hosts:
path: /home/user/.ssh/known_hosts
host: git.example.com
state: absent