Reputation: 159
I have an Ansible Playbook that is meant to create an Apache server locally on my machine. However, everytime I try running the playbook I get the following error messages:
[WARNING]: Could not match supplied host pattern, ignoring: apache
skipping: no hosts matched
This is what my Ansible Playbook looks like:
- hosts: apache
tasks:
- name: install apache2
apt: name=apache2 update_cache=yes state=latest
And this is what my ansible.cfg
and hosts
files look like:
ansible.cfg:
[defaults]
hostfile = hosts
inventory = /etc/ansible/hosts
hosts:
myserver ansible_host=127.0.0.1 ansible_user=ubuntu ansible_connection=local
This is all on an Ubuntu VM, if that matters. What am I doing wrong?
Edit: Alright, I no longer get that error after doing Shraddheya's fix, but now I am getting this error:
fatal: [myserver]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"ansible_facts": {discovered_interpreter_python": "/usr/bin/python3"}, "failed": true, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules fialed to execute: ansible.legacy.setup\n"}
Upvotes: 0
Views: 1020
Reputation: 187
Alter your hosts file a little to include myserver
in apache
hosts-group,
hosts
file must read:
[apache]
myserver ansible_host=127.0.0.1 ansible_user=ubuntu ansible_connection=local
Upvotes: 2