Ansible “如何解决警告”;无法匹配提供的主机模式,忽略:<;计算机主机名>;?
我正在尝试使用Ansible自动化我的工作站。我一直在做介绍。但是我一直使用Ansible “如何解决警告”;无法匹配提供的主机模式,忽略:<;计算机主机名>;?,ansible,ansible-pull,Ansible,Ansible Pull,我正在尝试使用Ansible自动化我的工作站。我一直在做介绍。但是我一直使用ansible pull命令收到警告 执行sudo ansible pull-U后https://github.com/plsergent/setup-user-friendly.git我收到[警告]:无法匹配提供的主机模式,忽略: 这是我的/etc/ansible/hosts文件: [localhost] 127.0.0.1 [localhost:vars] ansible_connection=local - h
ansible pull
命令收到警告
执行sudo ansible pull-U后https://github.com/plsergent/setup-user-friendly.git
我收到[警告]:无法匹配提供的主机模式,忽略:
这是我的/etc/ansible/hosts
文件:
[localhost]
127.0.0.1
[localhost:vars]
ansible_connection=local
- 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
和我的local.yml
文件:
[localhost]
127.0.0.1
[localhost:vars]
ansible_connection=local
- 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运行我的playbook时,没有任何警告:
sudo ansible playbook local.yml
有没有办法摆脱这个警告
您之所以会收到警告,是因为ansible pull
生成了一个命令行,其中包含一个--limit
选项,该选项是:
其中platform.node()
返回系统节点名(即uname-n
的输出),而socket.getfqdn()
尝试返回系统的完全限定域名。这意味着ansible命令行将如下所示:
ansible-playbook -l localhost,yourhostname.example.com,yourhostname,127.0.0.1 ...
$ 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
如果在--limit
参数中提供的主机名与资源清册中的主机不匹配,则会出现无法匹配提供的主机模式的错误。你可以这样复制:
ansible-playbook -l localhost,yourhostname.example.com,yourhostname,127.0.0.1 ...
$ 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资源清册中,从而避免警告。您可以将主机包括在内:
ansible-pull -i localhost,myhostname -U ...
或者,您可以将其显式指向现有库存文件:
ansible-pull -i /etc/ansible/hosts -U ...
要添加到@larsks answer中,似乎使用带有ansible pull的动态清单将产生警告,即使指定的主机名包含在动态清单脚本的结果中。解决方法是如前所述将主机名添加到-i中。注意:当“myhost”和“myhost.example.com”都在资源清册中时,ansible pull似乎对有多少台主机感到困惑,可能会运行两次Play或roles(一次在myhost上,另一次在myhost.example.com上),或者在一个名字上运行一些播放,在另一个名字上运行其他播放,同时产生一个意外的执行顺序。如果其他人被困在这个问题上:这不起作用:ansible pull-i myhostname-U。。。因为ansible不会将其解释为主机列表,所以您需要执行以下操作:ansible pull-i myhostname,-U。。。(注意后面的逗号)