Using check mode
Although you might be confident in the code you have written, it still pays to test it before running it for real in a production environment. In such cases, it is a good idea to be able to run your code, but with a safety net in place. This is what check mode is for. Follow these steps:
- First of all, we need to create an easy playbook to test this feature. Let’s create a playbook called
check-mode.yaml
that contains the following content:--- - hosts: localhost tasks: - name: Touch a file ansible.builtin.file: path: /tmp/myfile state: touch
- Now, we can run the playbook in check mode by specifying the
--check
option in the invocation:$ ansible-playbook check-mode.yaml --check
This will output everything as if it were really performing the operation, as follows:
PLAY [localhost] *******************************************...