
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