I have an Ansible role to install/activate Trendmicro. In the task, there’s one action did that activation by calling a bash command —
- name: Execute /opt/imal/bin/dsupdstat.sh
ansible.builtin.command: /opt/imal/bin/dsupdstat.sh
changed_when: true
failed_when: false
But since this dsupdstat.sh always needs to create a lock file at beginning and delete it at the end. So the Ansible Molecule test keeps failing on it with a “idempotence” error… But that lock file creation/deletion is inevitable. So it looks that no hope to pass this Molecule test even if I marked that action with changed_when: true
…
Now I have to use this to ignore running that action in molecule test —
- name: Execute /opt/imal/bin/dsupdstat.sh
ansible.builtin.command: /opt/imal/bin/dsupdstat.sh
when: not lookup('env', 'MOLECULE_SCENARIO') is defined
changed_when: true
failed_when: false
But I think — will it be any better method to let molecule to understand this action must do system change and let it pass?
1
Try the following, but first make sure the .sh script is executable.
- name: Execute /opt/imal/bin/dsupdstat.sh
ansible.builtin.command:
cmd: /opt/imal/bin/dsupdstat.sh
when: lookup('env', 'MOLECULE_SCENARIO') is not defined
changed_when: true
failed_when: false
1