After installing a software on the remote machine, and registering the task called “register: InstallCSQS” , I did a debug message and got the following:
ok: [sqldisktest] => {
“msg”: {
“changed”: true,
“failed”: false,
“rc”: 0,
“stderr”: “”,
“stderr_lines”: ,
“stdout”: “Installing Qualys and Crowdstrike on SQLDISKTEST\r\nWindows Sensor installed successfully.\r\nQualys installed successfully.\r\n”,
“stdout_lines”: [
“Installing Qualys and Crowdstrike on SQLDISKTEST”,
“Windows Sensor installed successfully.”,
“Qualys installed successfully.”
]
}
}
But when I add the below condition to my task, it fails:
changed_when: “‘Installing Qualys and Crowdstrike’ not in InstallCSQS.stdout”
error:
fatal: [sqldisktest]: FAILED! => {
“changed”: true,
“changed_when_result”: “The conditional check ‘‘Installing Qualys and Crowdstrike’ not in InstallCSQS.stdout’ failed. The error was: error while evaluating conditional (‘Installing Qualys and Crowdstrike’ not in InstallCSQS.stdout): ‘InstallCSQS’ is undefined”,
“checksum”: “ad4eb17ea1feee3bf9fbbf567dba6ce162ce1f0c”,
“dest”: “C:\Scripts\WindowsSensor.exe”,
“operation”: “file_copy”,
“original_basename”: “WindowsSensor.exe”,
“size”: 52183848,
“src”: “/etc/ansible/roles/InstallCSQS/files/WindowsSensor.exe”
}
playbook below:
-
name: Copy Crowdstrike Installer
ansible.windows.win_copy:
src: /etc/ansible/roles/InstallCSQS/files/WindowsSensor.exe
dest: C:\Scripts\WindowsSensor.exe
register: InstallCSQS
changed_when: “‘Installing Qualys and Crowdstrike’ not in InstallCSQS.stdout” -
name: Copy Qualys Installer
ansible.windows.win_copy:
src: /etc/ansible/roles/InstallCSQS/files/QualysCloudAgent.exe
dest: C:\Scripts\QualysCloudAgent.exe
register: InstallCSQS
changed_when: “‘Installing Qualys and Crowdstrike’ not in InstallCSQS.stdout”
execute PS script, and register the result in the variable named script_run
- name: Install Crowdstrike and Qualys
ansible.builtin.script: /etc/ansible/roles/onprembaseline/files/Qualys_Crowdstrike_installation.ps1
#register: script_run
register: InstallCSQS
changed_when: “‘Installing Qualys and Crowdstrike’ not in InstallCSQS.stdout”
debugs the stdout_lines property of the variable named InstallCSQS in above task
-
debug:
msg: “{{InstallCSQS}}” -
name: Remove Crowdstrike Installer
ansible.windows.win_file:
path: C:\Scripts\WindowsSensor.exe
state: absent
register: InstallCSQS
changed_when: “‘Installing Qualys and Crowdstrike’ not in InstallCSQS.stdout” -
name: Remove Qualys Installer
ansible.windows.win_file:
path: C:\Scripts\QualysCloudAgent.exe
state: absent
register: InstallCSQS
changed_when: “‘Installing Qualys and Crowdstrike’ not in InstallCSQS.stdout”