roles defined after include statement are ignored

I have a playbook which looks like this

  • hosts: all
    include: rails-servers.yml
    roles:
  • statsd
  • app

The roles in rails-servers.yml are executed. but app & statsd roles are not executed by ansible (using 1.5).
If I remove the include statement it gets executed. I get no errors when I run ansible. The roles are silently ignored.

rails-servers is a common playbook and this particular server needs some extra roles (statsd and app). What’s the

idiomatic way of doing it in ansible?

There is no play level include statement – it simply doesn’t exist.

You don’t include roles files, you just list them in the roles section and they are loaded out of the configured roles path.

What version of Ansible are you running? I would have expected this invalid keyword to raise an error in recent versions.

Solved. This was a syntax problem.

This works

file: site.yml

  • hosts: all
    include: rails-servers.yml

file: rail-servers.yml

  • hosts: all
    roles:
  • mysql
  • ruby
  • memcached

This does not work

file: site.yml

  • hosts: all

include: rails-servers.yml
roles:

  • statsd
  • app

file: rail-servers.yml

  • hosts: all
    roles:
  • mysql
  • ruby
  • memcached

When I do this, the roles in rails-servers.yml (mysql / ruby / memcached) are executed but the roles in site.yml (statsd / app) are silently ignored.

Solved it by changing the syntax to

file: site.yml

  • include: rails-servers.yml
  • hosts: all

roles:

  • statsd
  • app

file: rail-servers.yml

  • hosts: all
    roles:
  • mysql
  • ruby
  • memcached

This is not clearly explained in the documentation. Btw I think there was some misunderstanding of terminology in the original
email. I was using include at play level but at playbook level.