我正在学习Ansible,我已经按照教程在云上的VM上安装Wordpress。我的项目构建如下:
[.]
|_ playbook.yml
|_ ansible.cfg
|_ inventori.ini
|_ [roles]
|_ [server]
|_ ...
|_ [php]
|_ ...
|_ [mysql]
|_ ...
|_ [wordpress]
|_ ...
|_ [group_vars]
|_ [web]
|_ web.yml
|_ [host_vars]
|_ vm1Devops.yml
当我运行命令时:
ansible-playbook playbook.yml --ask-pass
我有以下错误:
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not
match 'all'
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo'
(default). This feature will be removed in version 2.9. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: Could not match supplied host pattern, ignoring: {VMIP_HERE}
PLAY [{VMIP_HERE}] ***********************************************************************************************
skipping: no hosts matched
PLAY RECAP *********************************************************************************************************
我不明白是什么意思,为什么ansible可以抓住我的IP,但告诉我主机列表是空的?我错过了什么 ?
在这里你可以看看我的playbook.yml:
- hosts:
- {VMIP_HERE}
roles:
- server
- php
- mysql
- wordpress
感谢您的支持。
Ansible使用单独的inventory files或dynamic inventory scripts或dynamic inventory plugins来了解在剧本中找到的任务的运行位置。
播放中的主机线与库存文件中配置的现有主机组或单个主机进行匹配。
尝试创建单独的清单文件,并在调用您的Playbook时引用它。
$ cat '{VMIP_HERE}' >> inventory
$ ansible-playbook -i inventory playbook.yml --ask-pass
另外,我不相信支持在播放中指定主机列表的格式。
更改
- hosts:
- {VMIP_HERE}
至
- hosts: {VMIP_HERE}
如果您想针对主机或主机组列表运行游戏,可以使用冒号':'将它们分开
- name: Run some tasks
hosts: group_one:group_two:group_three
gathers_facts: false
become: false
tasks:
- name: Print hello world
debug:
msg: "Hello world"