Firstly, I've seen lots of similarly tagged posts but nothing that works.. I have an existing Ansible host that I successfully use to deploy software to other servers. I wanted to setup a test environment using Vagrant to run my existing playbook(s) without any changes.
I've installed Ansible and Vagrant on a different server and copied over the playbook, inventory and group/host vars files.
However, when I run vagrant up
which invokes the playbook on the Vagrant host, using an Ansible (remote) provisioner, it gives the following message when running against hosts: localhost
PLAY [Set fact for later use] **************************************************
skipping: no hosts matched
The playbook (extract) looks like this:
- name: Set fact for later use
hosts: localhost
tasks:
- name: set number of hosts for later use
set_fact: num_hosts="{{ groups[tagname] | length }}"
I've also tried:
- name: Set fact for later use
hosts: 127.0.0.1
connection: local
tasks:
- name: set number of hosts for later use
set_fact: num_hosts="{{ groups[tagname] | length }}"
My static inventory (extract) looks like this:
'# Ungrouped hosts, specify before any group headers.
localhost ansible_connection=local
I've tried dynamic inventory and various combinations of localhost
/127.0.0.1
in the playbook and the inventory file but the step is always skipped on the Vagrant host.