Calling iris merge from Ansible
Does anyone know if iris merge can be called from Ansible. I have tried a couple of ways, but it doesn't seem to actually run the command on the target even though Ansible outputs it was successful.
Ansible Play:
- name: Install Iris
hosts: "{{ host_group }}"
serial: 1
remote_user: cotelmer
gather_facts: yes
vars:
- instance_type: "{{ inst_type }}"
roles:
- disable_new_bus_rule_editor
Ansible task:
- name: Run iris merge to disable application
ansible.builtin.shell: |
set timout 15
spawn bash -c "iris merge {{ item }}{{ hostvars[inventory_hostname].env }}{{ hostvars[inventory_hostname].failover_member_id }} /WORK/{{ item }}/deploy/cpf_merge_files/all_disable_application.mergefile /{{ item }}/{{ item }}{{ hostvars[inventory_hostname].env }}{{ hostvars[inventory_hostname].failover_member_id }}/iris.cpf"
expect "Username: "
send "hsadmin\n"
expect "Password: "
send "{{ pwd }}"
expect eof
args:
executable: /usr/bin/expect
with_items:
- "{{ instance_type }}"
register: iris_merge_output # Capture the output from the module
changed_when: iris_merge_output != 0 # <- Uses the return code to define when the task has changed.
- name: printing iris_output
ansible.builtin.debug:
var: iris_merge_output
Output of task:
changed: [lp-itfuat04] => (item=CLIN) => {
"ansible_loop_var": "item",
"changed": true,
"cmd": "set timout 15\nspawn bash -c \nsend \"iris merge CLINUAT04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINUAT04/iris.cpf\"\nexpect \"Username: \"\nsend \"hsadmin\\n\"\nexpect \"Password: \"\nsend \" \"\nexpect eof\n",
"delta": "0:00:00.009829",
"end": "2025-03-19 11:39:45.088939",
"invocation": {
"module_args": {
"_raw_params": "set timout 15\nspawn bash -c \nsend \"iris merge CLINUAT04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINUAT04/iris.cpf\"\nexpect \"Username: \"\nsend \"hsadmin\\n\"\nexpect \"Password: \"\nsend \"Adm4uat14\"\nexpect eof\n",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": "/usr/bin/expect",
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"item": "CLIN",
"rc": 0,
"start": "2025-03-19 11:39:45.079110",
"stderr": "send: spawn id exp5 not open\n while executing\n\"send \"hsadmin\\n\"\"",
"stderr_lines": [
"send: spawn id exp5 not open",
" while executing",
"\"send \"hsadmin\\n\"\""
],
"stdout": "spawn bash -c\r\niris merge CLINUAT04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINUAT04/iris.cpfbash: -c: option requires an argument",
"stdout_lines": [
"spawn bash -c",
"iris merge CLINUAT04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINUAT04/iris.cpfbash: -c: option requires an argument"
]
}
Content of all_disable_application.mergefile:
[Actions]
ModifyApplication:Name=/ui/interop/rule-editor,Enabled=0
Comments
I think it would be better to use the Ansible expect module:
ansible.builtin.expect module
Documentation is here:
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/exp…
I had the same issue happen when using the Ansible expect module.
Task:
- name: Run iris merge with ansible expect to disable application
ansible.builtin.expect:
command: "iris merge {{ item }}{{ hostvars[inventory_hostname].env }}{{ hostvars[inventory_hostname].failover_member_id }} /WORK/{{ item }}/deploy/cpf_merge_files/all_disable_application.mergefile /{{ item }}/{{ item }}{{ hostvars[inventory_hostname].env }}{{ hostvars[inventory_hostname].failover_member_id }}/iris.cpf"
responses:
"Username: ":
- "hsadmin\n"
"Password: ":
- "{{ pwd }}"
timeout: 1
with_items:
- "{{ instance_type }}"
register: iris_merge_output # Capture the output from the module
changed_when: iris_merge_output != 0 # <- Uses the return code to define when the task has changed.
Output:
2025-03-20 10:06:17,297 p=3052743 u=cotelmer n=ansible | ok: [lp-itfqa04] => {
"iris_merge_output": {
"changed": true,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": true,
"cmd": "iris merge CLINQA04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINQA04/iris.cpf",
"delta": "0:00:01.212244",
"end": "2025-03-20 10:06:17.125457",
"failed": false,
"invocation": {
"module_args": {
"chdir": null,
"command": "iris merge CLINQA04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINQA04/iris.cpf",
"creates": null,
"echo": false,
"removes": null,
"responses": {
"Password: ": [
" " <- Removed for pasting of output.
],
"Username: ": [
"hsadmin\n"
]
},
"timeout": 1
}
},
"item": "CLIN",
"rc": 0,
"start": "2025-03-20 10:06:15.913213",
"stdout": "\r\nUsername: hsadmin\r\nPassword: *********",
"stdout_lines": [
"",
"Username: hsadmin",
"Password: *********"
]
}
]
}
}
2025-03-20 10:06:17,298 p=3052743 u=cotelmer n=ansible | META: ran handlers
2025-03-20 10:06:17,298 p=3052743 u=cotelmer n=ansible | META: ran handlers
Content of all_disable_application.mergefile:
[Actions]
ModifyApplication:Name=/ui/interop/rule-editor,Enabled=0
In the portal there was no change.
I just realized the ansible output I put in my original post was incorrect. I re-ran it just now. Here is the correct output which is still having the same issue of running successfully, but the change is not seen in the management portal.
Output:
2025-03-20 10:36:00,354 p=3058295 u=cotelmer n=ansible | ok: [lp-itfuat04] => {
"iris_merge_output": {
"changed": true,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": true,
"cmd": "set timout 15\nspawn bash -c \"iris merge CLINUAT04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINUAT04/iris.cpf\"\nexpect \"Username: \"\nsend \"hsadmin\\n\"\nexpect \"Password: \"\nsend \"Adm4uat14\"\nexpect eof\n",
"delta": "0:00:10.031555",
"end": "2025-03-20 10:36:00.200962",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "set timout 15\nspawn bash -c \"iris merge CLINUAT04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINUAT04/iris.cpf\"\nexpect \"Username: \"\nsend \"hsadmin\\n\"\nexpect \"Password: \"\nsend \"Adm4uat14\"\nexpect eof\n",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": "/usr/bin/expect",
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"item": "CLIN",
"rc": 0,
"start": "2025-03-20 10:35:50.169407",
"stderr": "",
"stderr_lines": [],
"stdout": "spawn bash -c iris merge CLINUAT04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINUAT04/iris.cpf\r\n\r\nUsername: hsadmin\r\nPassword: *********",
"stdout_lines": [
"spawn bash -c iris merge CLINUAT04 /WORK/CLIN/deploy/cpf_merge_files/all_disable_application.mergefile /CLIN/CLINUAT04/iris.cpf",
"",
"Username: hsadmin",
"Password: *********"
]
}
]
}
}
2025-03-20 10:36:00,355 p=3058295 u=cotelmer n=ansible | META: ran handlers
2025-03-20 10:36:00,355 p=3058295 u=cotelmer n=ansible | META: ran handlers
Hi, I had a session at last years global summit on Ansible. I gave an example of doing CPF merge.
https://community.intersystems.com/post/ansible-modules-and-iris-demo