March 2019
Intermediate to advanced
412 pages
9h 49m
English
Detecting when check mode is active is very easy. The module object will have a check_mode attribute, which will be set to Boolean value true when check mode is active. In our module, we want to detect whether check mode is active before performing the copy. We can simply move the copy action into an if statement to avoid copying when check mode is active. No further changes to the module are necessary beyond this:
if not module.check_mode:
shutil.copy(module.params['source'],
module.params['dest'])
Now, we can run our playbook and add the -C argument to our execution. This argument engages check mode. We'll also test to ensure that the playbook did not actually create and copy the files. Let's take a look at the following ...
Read now
Unlock full access