I have a register
task to test for the installation of a package:
tasks:
- name: test for nginx
command: dpkg -s nginx-common
register
It is the command
module causing the changed state, not the register
parameter.
You can set changed_when: to something that is only true when something changed (also look at failed_when). If your task don't change anything, you might want to set check_mode as well. (Especially if other steps depend on the value)
This gives:
tasks:
- name: test for nginx
command: dpkg -s nginx-common
register: nginx_installed
changed_when: False
failed_when: False # dpkg -s returns 1 when packages is not found
check_mode: yes # this can safely run in check_mode
It’s described in official documentation here.
tasks:
- name: test for nginx
command: dpkg -s nginx-common
register: nginx_installed
changed_when: false