运行 ansible playbook 时缺少主机信息
missing host information when running ansible playbook
我在目录中有一个 ansbile.cfg 文件和一个主机文件。在同一目录中,我有一个 test_playbook.yml 文件。三者皆抄于下。当我 运行 ping (ad-hoc) 命令时,我得到了成功的响应。但是,当我尝试 运行ning ansible-playbook 命令时,响应如下:
[WARNING]: Host file not found: testserver
[WARNING]: provided hosts list is empty, only localhost is available
skipping: no hosts matched
ansible.cfg
[defaults]
hostfile = hosts
remote_user = testuser
##private_key_file = .vagrant/machines/default/virtualbox/private_key
##host_key_checking = False
主机
[webservers]
testserver ansible_ssh_host=ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com ansible_ssh_port=1234
test_playbook.yml
---
- hosts: all
remote_user: testuser
become: yes
become_user: testuser
tasks:
- group:
name: devops
state: present
- name: create devops user with admin privileges
user:
name: devops
comment: "Devops User"
uid: 2001
groups: devops
我运行ning的命令如下:
ansible-playbook test_playbook.yml -i testserver -vvv
响应:
知道我配置有误吗?
-i
指定您的清单文件,而不是主机。所以应该是-i hosts
.
ansible-playbook test_playbook.yml -i hosts
您也可以直接传递主机,但这样您将不会拥有清单文件中定义的行为主机变量:
ansible-playbook test_playbook.yml -i testserver,
,
使 ansible 将其视为主机列表,否则将其视为文件名。
如果你想限制它到主机 testserver
你可以使用 --limit
选项
ansible-playbook test_playbook.yml -i hosts --limit testserver
我在目录中有一个 ansbile.cfg 文件和一个主机文件。在同一目录中,我有一个 test_playbook.yml 文件。三者皆抄于下。当我 运行 ping (ad-hoc) 命令时,我得到了成功的响应。但是,当我尝试 运行ning ansible-playbook 命令时,响应如下:
[WARNING]: Host file not found: testserver
[WARNING]: provided hosts list is empty, only localhost is available
skipping: no hosts matched
ansible.cfg
[defaults]
hostfile = hosts
remote_user = testuser
##private_key_file = .vagrant/machines/default/virtualbox/private_key
##host_key_checking = False
主机
[webservers]
testserver ansible_ssh_host=ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com ansible_ssh_port=1234
test_playbook.yml
---
- hosts: all
remote_user: testuser
become: yes
become_user: testuser
tasks:
- group:
name: devops
state: present
- name: create devops user with admin privileges
user:
name: devops
comment: "Devops User"
uid: 2001
groups: devops
我运行ning的命令如下:
ansible-playbook test_playbook.yml -i testserver -vvv
响应:
知道我配置有误吗?
-i
指定您的清单文件,而不是主机。所以应该是-i hosts
.
ansible-playbook test_playbook.yml -i hosts
您也可以直接传递主机,但这样您将不会拥有清单文件中定义的行为主机变量:
ansible-playbook test_playbook.yml -i testserver,
,
使 ansible 将其视为主机列表,否则将其视为文件名。
如果你想限制它到主机 testserver
你可以使用 --limit
选项
ansible-playbook test_playbook.yml -i hosts --limit testserver