How to provide multiple responses to same prompt using Ansible expect module

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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật