我試圖構建一個網路應用程式來使用 ansible 管理我的服務器
現在我使用 Centos 7、PHP 7.4、Laravel 8 和 apache 來構建這個應用程式,我已經安裝了https://packagist.org/packages/asm/php-ansible composer 包,以便在我的專案中使用 ansible。
這是我的代碼:
$ansible = new Asm\Ansible\Ansible(
'/var/www/xxx/storage/ansible',
'',
''
);
$ansible->playbook()->play($myplaybookPath)->inventoryFile($myInventoryPath)->execute(function ($type, $buffer) {
if (Process::ERR === $type) {
echo 'ERR > '.$buffer ."<br/>";
} else {
echo 'OUT > '.$buffer."<br/>";
}
});
這是輸出:
OUT > PLAY [install nano] ************************************************************
OUT > TASK [Gathering Facts] *********************************************************
OUT > fatal: [xx.xx.14.139]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
OUT > PLAY RECAP *********************************************************************
OUT > xx.xx.14.139 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
OUT >
庫存檔案中的用戶名和密碼是正確的,我對其進行了多次測驗,還嘗試使用非常簡單的密碼使用新服務器。
我在谷歌上搜索了這個錯誤host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",我發現它是關于運行 ssh 的用戶的authorized_keys
我為我的 apache 用戶更改了 .ssh 檔案夾的權限和模式 /var/user/share/httpd/.ssh
購買此錯誤仍然存??在,我不知道如何解決此問題。
感謝幫助
更新
這與我的 Web 服務器配置無關,有關 apache 和 PHP 的一切都可以。
我使用 ansible-playbook 直接從終端運行我的劇本:
ansible-playbook /var/www/xxx/storage/ansible/playbooks/install_nano -i /var/www/xxx/storage/ansible/inventories/testInventory -vvv
我遇到了同樣的錯誤,我猜是關于 InventoryFile 中的 Auth 資訊
ansible-playbook 2.9.25
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /var/www/xxx/storage/ansible/inventories/testInventory as it did not pass its verify_file() method
auto declined parsing /var/www/xxx/storage/ansible/inventories/testInventory as it did not pass its verify_file() method
Parsed /var/www/xxx/storage/ansible/inventories/testInventory inventory source with ini plugin
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
Skipping callback 'json', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'null', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Skipping callback 'selective', as we already have a stdout callback.
Skipping callback 'skippy', as we already have a stdout callback.
Skipping callback 'stderr', as we already have a stdout callback.
Skipping callback 'unixy', as we already have a stdout callback.
Skipping callback 'yaml', as we already have a stdout callback.
PLAYBOOK: install nano ******************************************************************************************************************************************************************************
1 plays in /var/www/xxx/storage/ansible/playbooks/install nano
PLAY [install nano] *********************************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************************
task path: /var/www/xxx/storage/ansible/playbooks/install nano:2
<xx.xx.14.139> ESTABLISH SSH CONNECTION FOR USER: root
<xx.xx.14.139> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/a7f10d151a xx.xx.14.139 '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<xx.xx.14.139> (255, '', 'Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n')
fatal: [xx.xx.14.139]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
PLAY RECAP ******************************************************************************************************************************************************************************************
xx.xx.14.139 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
這是庫存檔案內容
[linux]
xx.xx.14.139
[linux:vars]
ansible_user=root
ansible_password=testPassword
另外,我嘗試 ansible_ssh_user / password 但它不起作用!
uj5u.com熱心網友回復:
這是解決方案
我在 ssh 連接中啟用了詳細模式,我注意到輸出的 SSH 請求不支持密碼身份驗證。
有 2 個 SSH 組態檔 /etc/ssh/sshd.conf 用于傳入請求和 /etc/ssh/ssh.cong 用于輸出,因此我從輸出請求組態檔中修復了該問題并啟用密碼身份驗證。
之后,我為我的 apache ssh 檔案(如密鑰和已知主機檔案)設定了權限。
之后,我在 laravel 中創建了一個命令,這樣我就可以使用 root 用戶和 Crond 運行我的 ansible playbook。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/399833.html
上一篇:如何保護使用JWT作為身份驗證的DRF創建的API的CSRF登錄和注冊端點(視圖)?
下一篇:Flask登錄與Apache快取
