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.ymlHowever, 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
- hosts: localhost
Vagrant.configure("2") do |config|config.vm.box = "centos/6"config.vm.network "private_network", ip: "192.168.33.10"config.vm.hostname = "myrole.vagrant.test.local"config.vm.provider "virtualbox" do |vb|vb.memory = "2048"endconfig.vm.provision "shell", inline: <<-SHELLprintf '[sensu]\nname=sensu\nbaseurl=https://sensu.global.ssl.fastly.net/yum/$releasever/$basearch/\ngpgcheck=0\nenabled=1' > /etc/yum.repos.d/sensu.repoyum update -yyum install libselinux-python sensu -ySHELLend