I am trying execute the following playbook using python script.
playbook = dict(
name = "Enable Site",
hosts = [host],
gather_facts = 'no',
tasks = [
dict(action=dict(
module='find', args=dict(paths="/etc/apache2/sites-enabled")), register='files_found'),
dict(action=dict(
module='shell', args="cd /etc/apache2/sites-enabled && a2dissite *"), register='shell_out', when='files_found.matched > 0'),
dict(action=dict(module='shell', args="a2ensite " + site_name), register='shell_out'),
dict(action=dict(module='service', args="name='apache2' state='reloaded'"), register='shell_out'),
]
)
This playbook basically checks if any apache site is enabled if yes then it disables them by removing all the files from /etc/apache2/sites-enabled.
The second task is supposed to be executed when the directory /etc/apache2/sites-enabled
is empty. But the "when" the condition is always evaluated to be true. Even if I write when="False"
. Also tried when="eval(False)"