Error by running an ansible-playbook with localhost

4.5k views Asked by At

I use a VM and Intershop 7.8 to run an ansible-playbook (using this tutorial ). After installing Ansible, copying the content of the repository and configuring it (as shown in the "quick installation guide"), I tried to run the ansible-playbook "setupci.yml" using the command ansible-playbook setupci.yml. Testing this the first time the error provided hosts list is empty, only localhost available occurred. Solving this by creating a "hosts.yml" file, in which I declared a hostname and using other commands to run the playbook, two new errors occurred.

I tried the following command in the ci-set-ansible-playbook directory:

$ --limit @[…]/ci-setup-ansible-playbook/setupci

I also tried:

$ ansible-playbook setupci.yml –connection=local

But both caused the errors:

fatal: [127.0.0.1]: FAILED! => {“changed”: false, “connection”: “close”, “content”: “\n \n 404 – Not Found

fatal: [127.0.0.1]: FAILED! => {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined.

1

There are 1 answers

4
Willem Evertse On BEST ANSWER

I guess ansible can't load the host vars for your host because the hostname that u defined in hosts.yml doesn't match the file name in /etc/ansible/host_vars/ directory. Maybe you didn't rename the sample.yml file, it needs to match the hostname.

See http://docs.ansible.com/ansible/latest/intro_inventory.html

[Update]

I tried out this ansible playbook on a docker centos 7 image. I also have some problem with getting it running correctly. However, i do get a connection. Make sure u copy the content of the git repo to /etc/ansible

/etc/ansible
-rw-r--r--. 1 root root  9191 Sep  7 12:22 LICENSE.md
-rw-r--r--. 1 root root  5672 Sep  7 12:22 README.asciidoc
-rw-r--r--. 1 root root   555 Sep  7 12:22 Vagrantfile
-rw-r--r--. 1 root root 18066 Jun  1 21:49 ansible.cfg
drwxr-xr-x. 2 root root    42 Sep  7 12:26 group_vars
-rw-r--r--. 1 root root  1050 Sep  7 12:31 hosts
-rw-r--r--. 1 root root    97 Sep  7 12:22 ishsystem.yml
-rw-r--r--. 1 root root  9191 Sep  7 12:22 license-2.0.txt
drwxr-xr-x. 9 root root  4096 Sep  7 12:22 roles
-rw-r--r--. 1 root root   138 Sep  7 12:39 setupci.ym

edit the hosts file

##content of hosts
ciserver ansible_connection=local

Check that ansible can connect to the host

ansible all -m ping
ciserver | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

copy the sample.yml in group_var to ciserver.yml (same name as in hosts) file and edit it.

/etc/ansible/group_vars 
-rw-r--r--. 1 root root 1882 Sep  7 12:26 ciserver.yml
-rw-r--r--. 1 root root 1873 Sep  7 12:22 sample.yml

Run the playbook

ansible-playbook setupci.yml

My scripts stops when it tried to start/stop the firewall. The service doesn't exist on centos so it fails. See if u can get this far.

fatal: [ciserver]: FAILED! => {"changed": false, "failed": true, "msg": "Could not find the requested service firewalld.service: host"}