1

I need to install nginx agent for openam using ansible.

while install the nginx_agent it asking multiple question while run the script,

     ************************************************************************
    Welcome to the OpenSSO Policy Agent for NGINX
    ************************************************************************

    Enter the URL where the OpenAM server is running.
    Please include the deployment URI also as shown below:
    (http://opensso.sample.com:58080/opensso)
    **OpenSSO server URL: sss**
    Enter the Agent profile name
    **Agent Profile Name: sss**
    Enter the password to be used for identifying the Agent.
    *THIS IS NOT PASSWORD FILE*
    **Agent Password:** 
    -----------------------------------------------
    SUMMARY OF YOUR RESPONSES
    -----------------------------------------------
    OpenSSO server URL : sss
    Agent Profile name : sss
    Agent Password:     sss
    **Continue with Installation?
    [y/N]: y**

I have used expect module in ansible:

- expect:
    command: sh /opt/nginx_agent/bin/agentadmin.sh
    responses:
        OpenSSO server URL: "http://openam.test.mobi:8080/openam"
        Agent Profile Name: "nginx"
        Agent Password: "test.mobi2"
        (^Con[^\n]*\n+[^\n]*)+: "y" 

But, its Continue with Installation? [y/N]:

takes, OpenSSO server URL: value see,

Reference:

     "stdout_lines": [
         "************************************************************************", 
         "Welcome to the OpenSSO Policy Agent for NGINX", 
         "************************************************************************", 
         "", 
         "Enter the URL where the OpenAM server is running.", 
         "Please include the deployment URI also as shown below:", 
         "(http://opensso.sample.com:58080/opensso)", 
         "OpenSSO server URL: Enter the Agent profile name", 
         "Agent Profile Name: Enter the password to be used for identifying the Agent.", 
         "*THIS IS NOT PASSWORD FILE*", 
         "Agent Password: ", 
         "-----------------------------------------------", 
         "SUMMARY OF YOUR RESPONSES", 
         "-----------------------------------------------", 
         "OpenSSO server URL : http://openam.test.mobi:8080/openam", 
         "Agent Profile name : nginx", 
         "Agent Password:     test.mobi2", 
         "Continue with Installation?", 
         "[y/N]: http://openam.test.mobi:8080/openam", 
         "test.mobi2"
     ]

What have I missed in this configuration?

2 Answers 2

0

I would try ignoring the Continue with Installation? and just match on the [y/N] line.

replace (^Con[^\n]*\n+[^\n]*)+: "y" with 'y/N' : 'y'

Ansible uses the pexpect module which doesn't always do what you would expect. For example, EOL is '\r\n', not '\n'.

See the docs here.

Here is a quick test:

/root/junk.sh
echo 'Enter the Agent profile name'
read -p "Agent Profile Name: " AGENT_PROFILE_NAME
echo $AGENT_PROFILE_NAME > junk.dat
echo "Continue with installation"
read -p "[y/N] : " CONFIRM
echo $CONFIRM >> junk.dat

play:
- expect:
    command: sh /root/junk.sh
    responses:
      'Profile Name' : "oook"
      'y/N' : 'y'

Here is an easier way to do it without using expect.

If you look at the agentadmin.sh script you will see that responses to all of the questions are stored in environment variables, i.e.

while [ -z ${OPENAM_URL} ]; do

If you pre-define all of them in the environment section of your playbook the script should run without any user intervention. No need for expect.

So something like:

environment:
  OPENAM_URL: whatever_1
  AGENT_PROFILE_NAME: whatever_2
  AGENT_PASSWORD: whatever_3
  CONFIRM: y

- shell: /opt/nginx_agent/bin/agentadmin.sh
2
  • i tried your way but, still i have same issue Commented Dec 28, 2016 at 12:32
  • Try running it with ansible-playbook -vvv playbook.yml.
    – glebaron
    Commented Dec 30, 2016 at 0:08
0

Work for ansible 2.7.7 and ubuntu 18.04:

---
- name: Install pexpect 4 Ubuntu
  when:
    - ansible_distribution == 'Ubuntu'
  become: yes
  block:
    - apt:
        name:
          - python-pexpect
          - python3-pexpect
          - python-setuptools
          # https://stackoverflow.com/a/51998238
          - python-pip
        state: latest
        install_recommends: yes
  tags:
    - linux
    - ubuntu
    - python
    - pip
    - expect
    - apt

- name: Install pexpect using pip
  when:
    - ansible_system == 'Linux'
  pip:
    name: pexpect
    state: latest
  tags:
    - linux
    - python
    - pip
    - expect

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .