
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
sudo nano /etc/ansible/hosts
將文件編輯為:
[網路伺服器] 192.168.27.1
[伺服器] host1 ansible_ssh_host: 192.168.27.1 然後
sudo mkdir /etc/ansible/group_vars
sudo nano /etc/ansible/group_vars/servers
Yaml 檔案建立為:
---
ansible_ssh_user: root
然後:
ansible -m ping all
我遇到的錯誤是:
ERROR! Attempted to read "/etc/ansible/hosts" as YAML: Syntax Error while loading YAML.
The error appears to have been in '/etc/ansible/hosts': line 46, column 1, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
[Webserver]
192.168.27.1
^ here
Attempted to read "/etc/ansible/hosts" as ini file: /etc/ansible/hosts:50: Expected key=value host variable assignment, got: 192.168.27.1
請幫我解決這個問題。
答案1
看起來一模一樣這
嘗試進入檔案並蒐索該行中放錯位置的空格。根本原因是/usr/local/etc/ansible/hosts
檔案中存在前導空格,解決方案是搜尋此類空格並將其刪除。論壇貼文的關鍵部分如下所示。
這是由
/usr/local/etc/ansible/hosts
庫存文件中帶有前導空格的註釋引起的。這是此 Ansible 版本的新行為!因此,如果您習慣在主機文件中編寫類似的內容:
[web] # legacy servers webserver-[1:2].company.com
將其更改為:
[web] # legacy servers webserver-[1:2].company.com
或者
[web] webserver-[1:2].company.com # legacy servers