I am using the Delinea adedit command (https://docs.delinea.com/online-help/server-suite/dev/adedit/commands.htm). After issuing the adedit command in a Linux CLI a > prompt is seen and I enter the following commands in succession:
>bind acme.com administrator password123
>package require ade_lib
>add_user_to_group ...
>quit
FYI, password123 is a false password.
I am attempting to code this in Ansible using the expect command like so:
- name: Delinea adedit generic prompt with multiple different responses
ansible.builtin.expect:
command: adedit
responses:
">":
- bind "{{domain_name}} {{ lookup('aws_ssm', '/ansible/windows/username', region='us-east-1') }} {{ lookup('aws_ssm', '/ansible/windows/password', region='us-east-1') }}"
- package require ade_lib
- add_user_to_group "{{instance_name}}$@{{domain_name}} "CN=SG-CFY-Delinea MFA Servers,OU=Computer Roles,OU=Centrify,DC=acme,DC=local""
- quit
and I get this response in Ansible:
changed: [SERVER01] => {"changed": true, "cmd": "adedit", "delta": "0:00:00.193347", "end": "2024-09-11 14:49:15.510734", "rc": 0, "start": "2024-09-11 14:49:15.317387", "stdout": "No entry for terminal type "unknown";rnusing dumb terminal settings.rn>bind "acme.local administrator password123"", "stdout_lines": ["No entry for terminal type "unknown";", "using dumb terminal settings.", ">bind "acme.local administrator password123""]}
It seems that all four commands are not issued in succession. What is incorrect in my Ansible code?
0
It looks like instead of using an expect
-like solution, you could do something like this and your commands to adedit
on standard input:
- name: Delinea adedit generic prompt with multiple different responses
ansible.builtin.command:
cmd: adedit
stdin: |
bind "{{domain_name}} {{ lookup('aws_ssm', '/ansible/windows/username', region='us-east-1') }} {{ lookup('aws_ssm', '/ansible/windows/password', region='us-east-1') }}"
package require ade_lib
add_user_to_group "{{instance_name}}$@{{domain_name}} "CN=SG-CFY-Delinea MFA Servers,OU=Computer Roles,OU=Centrify,DC=acme,DC=local""
quit
I don’t have any way to test this out, but reading through the docs this looks like a possibility.
3
I was able to get this working by creating a bash script with the adedit commands and running that. I think that worked because I need the correct environment to run adedit. So what I did was create this Jinja2 template called adedit.j2
#!/usr/bin/env adedit
package require ade_lib
bind {{domain_name}} {{ lookup('aws_ssm', '/ansible/windows/admgtosi/username', region='us-east-1') }} {{ lookup('aws_ssm', '/ansible/windows/admgtosi/password', region='us-east-1') }}
add_user_to_group {{instance_name}}$@{{domain_name}} "CN=SG-CFY-Delinea MFA Servers,OU=Computer Roles,OU=Centrify,DC=compucom,DC=local"
quit
Then I ran it with these Ansible tasks:
- name: Delinea - Template of adedit.sh bash script
ansible.builtin.template:
src: files/adedit.j2
dest: /tmp/adedit.sh
owner: root
group: root
mode: 0754
- name: Run the Delinea adedit.sh bash script
command: /tmp/adedit.sh
This worked.