From 62fe4cc3af5bf011b8e8dd92b1c4a640f1f25808 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 12 Apr 2013 20:46:12 -0400 Subject: [PATCH] Explain conditionals as applied to roles. I could also explain with_items but the scope questions are complex here, and it is better to include such loops inside the imported tasks. --- docsite/latest/rst/playbooks.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docsite/latest/rst/playbooks.rst b/docsite/latest/rst/playbooks.rst index 0a404966cc2..04be0ab86f4 100644 --- a/docsite/latest/rst/playbooks.rst +++ b/docsite/latest/rst/playbooks.rst @@ -473,6 +473,16 @@ Also, should you wish to parameterize roles, by adding variables, you can do so, - { role: foo_app_instance, dir: '/opt/a', port: 5000 } - { role: foo_app_instance, dir: '/opt/b', port: 5001 } +While it's probably not something you should do often, you can also conditionally apply roles like so:: + + --- + - hosts: webservers + roles: + - { role: some_role, when: "ansible_os_family == 'RedHat'" } + +This works by applying the conditional to every task in the role. Conditionals are covered later on in +the documentation. + Executing A Playbook ````````````````````