gpt4 book ai didi

ansible - 如何解决警告“无法匹配提供的主机模式,忽略 : ?

转载 作者:行者123 更新时间:2023-12-02 16:37:09 25 4
gpt4 key购买 nike

我正在尝试使用 Ansible 来自动化我的工作站。我一直在关注this tutorial作为介绍。但我不断收到使用 ansible-pull 的警告命令。

做完sudo ansible-pull -U https://github.com/plsergent/setup-user-friendly.git之后我得到[WARNING]: Could not match supplied host pattern, ignoring: <local machine hostname>

这是我的/etc/ansible/hosts文件:

[localhost]
127.0.0.1

[localhost:vars]
ansible_connection=local

还有我的local.yml文件:

- hosts: localhost
become: true
pre_tasks:
- name: update repositories
apt: update_cache=yes
changed_when: False

tasks:
- include: tasks/packages.yml
- include: tasks/users.yml
- include: tasks/cron.yml

有办法消除这个警告吗?

谢谢

注意:当我使用 ansible-playbook 运行我的剧本时,没有任何警告: sudo ansible-playbook local.yml

最佳答案

Is there a way to get rid of this warning ?

您收到警告是因为 ansible-pull 构建的命令行包含构建的 --limit 选项 like this :

node = platform.node()
host = socket.getfqdn()
limit_opts = 'localhost,%s,127.0.0.1' % ','.join(set([host, node, host.split('.')[0], node.split('.')[0]]))

其中 platform.node() 返回您的系统节点名称(即 uname -n 的输出)和 socket.getfqdn()尝试返回您系统的完全限定域名。这意味着 ansible 命令行将如下所示:

ansible-playbook -l localhost,yourhostname.example.com,yourhostname,127.0.0.1 ...

碰巧,当您在 --limit 参数中提供的主机名与 list 中的主机不匹配时,您会收到无法匹配提供的主机模式 错误。您可以像这样重现它:

$ ansible all -m ping  -l host-that-does-not-exist
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit
localhost does not match 'all'

[WARNING]: Could not match supplied host pattern, ignoring: host-that-does-not-exist

如果警告确实让您烦恼,您可以通过在 ansible-pull 命令中添加 -i 选项,将您的本地主机名显式包含在 ansible list 中来避免它线。您可以内联包含主机:

ansible-pull -i localhost,myhostname -U ...

或者您可以将其明确指向现有 list 文件:

ansible-pull -i /etc/ansible/hosts -U ...

关于ansible - 如何解决警告“无法匹配提供的主机模式,忽略 : <machine hostname>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55820887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com