So I’m struggling with the following.
I want to check if a certain directory exists (Tomcat instance directory) , if so I wan’t to stop the playbook since apparently the tomcat instance is already present.
I thought this should work:
`
name: create tomcat instance {{ tomcat_instance_name }} dir
file: path=“{{ tomcat_dir }}/instances/{{ tomcat_instance_name }}” state=directory
register: result
failed_when: result|ok
name: debug command result
debug: result
`
I expected that the var ‘result’ would contain the output like shown without -v (ok, changed, skipping) or perhaps with -v (changed:false/true etc etc)
However this is not the case. Debuging said var will give me “Hello World!”. Well Hello to you to, but it’s not being very helpful.
So the main question would be. How do you guys check if something already exists and get it to fail/skip if it does.
If you fail on file, that host should not hit the debug task below.
You can instead use the 'fail' module or set ignore_errors: true if
you need to do things afterwards. I'm not sure where you are getting
'hello world' from.
It is true that I shouldn’t hit the debug. In my example I forgot to remove the failed_when statement.
If removed I still get the Hello World. No matter what I debug. stdout,err,rc…
I’m not quite sure if a shell commando would work:
name: Check to see if the tomcat instance already exists shell: find /usr/local/tomcat/instances -name "{{ tomcat_instance_name}}" register: output
However this still gives “Hello World” when debugged.
Am I missing something?