我正在使用 Jenkins 上的 Ansible 插件,但出現了下一個錯誤:
> "Failed to connect to the host via ssh: Load key \"/etc/ansible/jenkinsPem\": Permission denied\r\nmadchabelo@targethost: Permission denied (publickey,password).", "unreachable": true}
我的主機檔案:
[targets]
targethost ansible_user=madchabelo ansible_private_key_file=/etc/ansible/jenkinsPem
mysqlhost ansible_user=madchabelo ansible_private_key_file=/etc/ansible/jenkinsPem
我的劇本:
---
- name: Playbook for jenkins
hosts: [targets]
tasks:
- name: hello world
shell: echo Hello World again
但如果我在 shell 上運行:
ansible-playbook -i /etc/ansible/hosts /etc/ansible/playbook/jenkinsansible.yaml
一切都好:
PLAY [Playbook for jenkins] *******************************************
TASK [Gathering Facts] ************************************************
[WARNING]: Platform linux on host targethost is using the discovered Python interpreter at /usr/bin/python3, but future installation of another Python interpreter
could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [targethost]
[DEPRECATION WARNING]: Distribution fedora 36 on host mysqlhost should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior Ansible
releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 2.12. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [mysqlhost]
TASK [hello world] ***************************************************
changed: [targethost]
changed: [mysqlhost]
PLAY RECAP ***********************************************************
mysqlhost: ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
targethost: ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
以下是 Jenkins 上的路徑:

uj5u.com熱心網友回復:
私鑰應存盤在 Jenkins 憑據中。
插件
在Build steps您問題的螢屏截圖中顯示的清單選項下應該有該Credentials選項(它可能不存在,因為未安裝 ssh-credentials 插件)。
應在此處找到已保存的憑據以供選擇。
現在應該毫無問題地執行劇本。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/510148.html
標籤:詹金斯SSH可靠的
下一篇:在同一個詹金斯管道上運行多個測驗
