
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 バージョンの新しい動作です。したがって、hosts ファイルに次のような内容を書く習慣がある場合:
[web] # legacy servers webserver-[1:2].company.com
次のように変更します:
[web] # legacy servers webserver-[1:2].company.com
または
[web] webserver-[1:2].company.com # legacy servers