This tasks fails with the same error. I’ve tried every iteration of “” ’ ’ and ()'s that I can think of, to no avail. Can someone lend a hand and point out my error here?
The file module that I was testing with doesn’t list a rc in it’s output when using -v.
The other issue is that the module I was trying to use this on originally was replace, which also doesn’t list rc when it succeeds.
`
hosts: all
tasks:
name: test task
replace:
dest: /foo/bar.txt
regexp: hello
replace: goodbye
register: result
failed_when: result.rc != 0 and result.rc != 257
`
(257 is the return code for file doesn’t exist)
This task works just fine when the dest doesn’t exist, but when the dest file does exist, no rc is returned and it throws the error about evaluating the condition.
Is there a way to account for both situations(when the dest file of the replace module doesn’t exist and when the file does exist and no return code is given)?
can you elaborate a bit on what it is you want to achieve? I’m a bit confused because the play in your first post does something completely different than the play in your second post.
It sounds like the file module without any “failed_when” conditions does what you ask, but that might not be true in your use-case.
Thanks for the response, and sorry for the confusion, I was trying to use simpler examples to explain the problem, but seemed to have failed.
I’m trying to use the replace module to update a bunch of weblogic files with the correct version after a new version of java has been deployed. However when the playbook is run for the first time on a server, the weblogic files don’t yet exist and I wanted to adjust the failed_when parameter such that when it says ‘file now found’ with return code 257, it didn’t mark the tasks failed, because that will be an expected outcome the first run.
I semi solved this for now by moving the replace task below the weblogic install tasks but for organizations sake, and in case I ever want to separate the weblogic install into another role, i’d like to be run this task without a failure when the files aren’t in place yet. The weblogic install takes care of the initial file configuration anyway, the replace task is to just to update them when the java version is changed.
I don’t have this project on github yet but here’s a larger snippet in case it helps.
So, in the long run I would recommend looking at making this “more idempotent”. Go the way you are going with register: wlinstall_result for all the Websphere setup tasks. Move them to a different yml file or role and only include it when Weblogic needs to be installed.
As a quick solution I would recommend adding an extra task that builds your list of files to be used with the replace command. That is easier said than done and unfortunately I don’t have the time right now to test it. Another idea would be to have two lists (one for newly deployed servers and one for servers that have all of the files.)