I'm trying to use Ansible to automate my workstation. I've been following this tutorial as an introduction. But I keep getting a warning using the ansible-pull command.
After doing sudo ansible-pull -U https://github.com/plsergent/setup-user-friendly.git i'm getting [WARNING]: Could not match supplied host pattern, ignoring: <local machine hostname>
Here is my /etc/ansible/hosts file :
[localhost]
127.0.0.1
[localhost:vars]
ansible_connection=local
and my local.yml file :
- 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
Is there a way to get rid of this warning ?
Thanks
Note:
I don't have any warning when I run my playbook using ansible-playbook:
sudo ansible-playbook local.yml
You're getting the warning because
ansible-pullbuilds a command line that includes a--limitoption that is built like this:Where
platform.node()returns your systems node name (i.e. the output ofuname -n) andsocket.getfqdn()attempts to return the fully qualified domain name of your system. This means that the ansible command line will look something like this:It so happens that when you provide a hostname in the
--limitargument that does not match a host in your inventory, you get theCould not match supplied host patternerror. You can reproduce that like this:If the warning really bothers you, you can avoid it by explicitly including your local hostname in the ansible inventory by adding a
-ioption to youransible-pullcommand line. You can either include the hosts inline:Or you can point it explicitly at an existing inventory file: