ожидаемое ожидание не работает для нескольких значений подсказок

4887
Rajkumar .E

Мне нужно установить агент nginx для openam, используя ansible.

при установке nginx_agent он задает несколько вопросов при запуске скрипта ,

 ************************************************************************ 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** 

Итак, я использую модуль ожидания в 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"  

Но продолжить его с установки? [Y / N]:

принимает, URL сервера OpenSSO: см. значение,

Ссылка:

 "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" ] 

Предложите мне, что мне не хватает в этой конфигурации. Как это исправить

0

1 ответ на вопрос

0
glebaron

Я бы попытался игнорировать Continue with Installation?и просто сопоставить на [y/N]линии.

заменить (^Con[^\n]*\n+[^\n]*)+: "y"на'y/N' : 'y'

Ansible использует модуль pexpect, который не всегда делает то, что вы ожидаете. Например, EOL есть '\r\n', а не '\n'.

Смотрите документы здесь .

Вот быстрый тест:

/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' 

Вот более простой способ сделать это без использования ожидаемого.

Если вы посмотрите на скрипт agentadmin.sh, то увидите, что ответы на все вопросы хранятся в переменных среды, т.е.

while [ -z $ ]; do 

Если вы предварительно определили все из них в разделе среды вашей игровой книги, сценарий должен выполняться без какого-либо вмешательства пользователя. Не нужно ожидать.

Так что-то вроде:

environment: OPENAM_URL: whatever_1 AGENT_PROFILE_NAME: whatever_2 AGENT_PASSWORD: whatever_3 CONFIRM: y  - shell: /opt/nginx_agent/bin/agentadmin.sh 
Я попробовал свой путь, но, тем не менее, у меня та же проблема Rajkumar .E 7 лет назад 0
Попробуйте запустить его с помощью ansible-playbook -vvv playbook.yml. glebaron 7 лет назад 0

Похожие вопросы