ansible-galaxy generates the correct host name (localhost), so the docs on 
the website seem to be out of date.

But the problem was that the role being developed is not under tests/roles. 
I added a symlink from tests/roles to the root directory of the role and 
that fixed the problem.


On Tuesday, May 22, 2018 at 1:22:28 PM UTC+10, BIJAY PARIDA wrote:
>
> Host example is not a valid host name.
>
> - hosts: localhost
>
> On Tuesday, 22 May 2018 07:31:24 UTC+5:30, Behrang wrote:
>>
>> Hi,
>>
>> In the docs <https://galaxy.ansible.com/intro#role-test>, it is written 
>> that:
>>
>> Test It
>>
>> The actual work to be performed gets added as playbook tasks to 
>> *tasks/main.yml*. Once you've added some tasks, create a playbook to 
>> test the role and insure it works. Here's a simple playbook to execute your 
>> new role:
>>
>>
>> # test.yml
>> # test playbook
>> - hosts: example
>>   roles:
>>   - { role: acme }
>>  
>>
>> $ ansible-playbook test.yml
>>
>> However, this won't work as the test playbook directory doesn't have 
>> access to the role.
>>
>>
>> $ ansible-galaxy init sample-role
>> - sample-role was created successfully
>>
>> $ cd sample-role/tests/
>>
>> $ ansible-playbook test.yml
>>  [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
>>
>>  [WARNING]: No inventory was parsed, only implicit localhost is available
>>
>>  [WARNING]: provided hosts list is empty, only localhost is available. Note 
>> that the implicit localhost does not match 'all'
>>
>> ERROR! the role 'sample-role' was not found in 
>> /Users/grey.behrangs/Documents/Projects/ansible-roles/sample-role/tests/roles:/Users/grey.behrangs/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/Users/grey.behrangs/Documents/Projects/ansible-roles/sample-role/tests
>>
>> The error appears to have been in 
>> '/Users/grey.behrangs/Documents/Projects/ansible-roles/sample-role/tests/test.yml':
>>  line 5, column 7, but may
>> be elsewhere in the file depending on the exact syntax problem.
>>
>> The offending line appears to be:
>>
>>   roles:
>>     - sample-role
>>       ^ here
>>
>>
>> Is there a quick way to test newly created roles?
>>
>> Cheers,
>> Behrang
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fb265ec0-8389-4f8e-b6ff-f0c872c46a3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to