Ansible Shell With Expect

49 views
Skip to first unread message

Freddie Eisa

unread,
Jan 15, 2019, 10:10:34 AM1/15/19
to Ansible Project
We are trying the following 


- name: Configure Orion Agent

  shell: |

    set timeout 30

    spawn service swiagentd init


    expect "Choose an option>"

    send "2"


    exit 0

  args:

    executable: /usr/bin/expect



We are able to spawn the process but it looks like the expect part never works 


    "changed": true, 

    "cmd": "set timeout 30\n spawn service swiagentd init\n\n expect \"Choose an option>\"\n send \"2\"\n\n exit 0", 

    "delta": "0:00:00.132261", 

    "end": "2019-01-15 10:08:43.611145", 

    "invocation": {

        "module_args": {

            "_raw_params": "set timeout 30\n spawn service swiagentd init\n\n expect \"Choose an option>\"\n send \"2\"\n\n exit 0", 

            "_uses_shell": true, 

            "argv": null, 

            "chdir": null, 

            "creates": null, 

            "executable": "/usr/bin/expect", 

            "removes": null, 

            "stdin": null, 

            "warn": true

        }

    }, 

    "rc": 0, 

    "start": "2019-01-15 10:08:43.478884", 

    "stderr": "", 

    "stderr_lines": [], 

    "stdout": "spawn service swiagentd init\r\n\r\nSolarWinds Orion Agent [2.0.0.70] Settings, OpenSSL [OpenSSL 1.0.2k-fips  26 Jan 2017]\r\n   0. Cancel and Exit without Saving\r\n   1. Agent Mode (1 - Agent Initiated, 0 - Server Initiated)  [1]\r\n   2. Orion Poller Hostname/IP  [localhost]\r\n   3. Orion Poller Port         [17778]\r\n   4. Orion Username            [admin]\r\n   5. Orion Password            []\r\n   6. Proxy Settings...         [mode=disabled]\r\n   7. Save Changes and Exit\r\n\r\nChoose an option>", 

    "stdout_lines": [

        "spawn service swiagentd init", 

        "", 

        "SolarWinds Orion Agent [2.0.0.70] Settings, OpenSSL [OpenSSL 1.0.2k-fips  26 Jan 2017]", 

        "   0. Cancel and Exit without Saving", 

        "   1. Agent Mode (1 - Agent Initiated, 0 - Server Initiated)  [1]", 

        "   2. Orion Poller Hostname/IP  [localhost]", 

        "   3. Orion Poller Port         [17778]", 

        "   4. Orion Username            [admin]", 

        "   5. Orion Password            []", 

        "   6. Proxy Settings...         [mode=disabled]", 

        "   7. Save Changes and Exit", 

        "", 

        "Choose an option>"

    ]

}

Freddie Eisa

unread,
Jan 15, 2019, 10:48:24 AM1/15/19
to ansible...@googlegroups.com
We are a little further, the second expect is not working

- name: Configure Orion Agent 
  shell: |
    set timeout 30
    spawn service swiagentd init

    expect "Choose an option>"
    send "2\n" 
    expect "Enter Orion Poller Hostname/IP"
    send "orion.hq.domain.com"

  

    exit 0
  args:
    executable: /usr/bin/expect

changed: [vm-host04.hq.domain.com] => {
    "changed": true, 
    "cmd": "set timeout 30\n spawn service swiagentd init\n\n expect \"Choose an option>\"\n send \"2\\n\"\n expect \"Enter Orion Poller Hostname/IP\"\n send \"orion.hq.domain.com\"\n\n exit 0", 
    "delta": "0:00:00.124392", 
    "end": "2019-01-15 10:46:13.836854", 
    "invocation": {
        "module_args": {
            "_raw_params": "set timeout 30\n spawn service swiagentd init\n\n expect \"Choose an option>\"\n send \"2\\n\"\n expect \"Enter Orion Poller Hostname/IP\"\n send \"orion.hq.domain.com\"\n\n exit 0", 
            "_uses_shell": true, 
            "argv": null, 
            "chdir": null, 
            "creates": null, 
            "executable": "/usr/bin/expect", 
            "removes": null, 
            "stdin": null, 
            "warn": true
        }
    }, 
    "rc": 0, 
    "start": "2019-01-15 10:46:13.712462", 
    "stderr": "", 
    "stderr_lines": [], 
    "stdout": "spawn service swiagentd init\r\n\r\nSolarWinds Orion Agent [2.0.0.70] Settings, OpenSSL [OpenSSL 1.0.2k-fips  26 Jan 2017]\r\n   0. Cancel and Exit without Saving\r\n   1. Agent Mode (1 - Agent Initiated, 0 - Server Initiated)  [1]\r\n   2. Orion Poller Hostname/IP  [localhost]\r\n   3. Orion Poller Port         [17778]\r\n   4. Orion Username            [admin]\r\n   5. Orion Password            []\r\n   6. Proxy Settings...         [mode=disabled]\r\n   7. Save Changes and Exit\r\n\r\nChoose an option>2\r\nEnter Orion Poller Hostname/IP", 
    "stdout_lines": [
        "spawn service swiagentd init", 
        "", 
        "SolarWinds Orion Agent [2.0.0.70] Settings, OpenSSL [OpenSSL 1.0.2k-fips  26 Jan 2017]", 
        "   0. Cancel and Exit without Saving", 
        "   1. Agent Mode (1 - Agent Initiated, 0 - Server Initiated)  [1]", 
        "   2. Orion Poller Hostname/IP  [localhost]", 
        "   3. Orion Poller Port         [17778]", 
        "   4. Orion Username            [admin]", 
        "   5. Orion Password            []", 
        "   6. Proxy Settings...         [mode=disabled]", 
        "   7. Save Changes and Exit", 
        "", 
        "Choose an option>2", 
        "Enter Orion Poller Hostname/IP"


-- 
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7f439e10-1883-46c4-8f0b-d069dfb8938e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Freddie Eisa

unread,
Jan 15, 2019, 12:19:39 PM1/15/19
to ansible...@googlegroups.com
One more update. Looks like most of this is working now besides the final part. My assumption is I need to wildcard or use a different escape character. Please provide any feedback 

- name: Configure Orion Agent 
  shell: |
    set timeout 30
    spawn service swiagentd init

    expect "Choose an option>"
    send "2\n" 
    expect "Enter Orion Poller Hostname/IP"
    send "orion.hq.crabel.com\n"
    expect "Choose an option>"
    send "4\n"  
    expect "Enter Orion Username"
    send "orion_agent\n" 
    expect "Choose an option>"
    send "5\n"
    expect "Enter Orion Password"
    send "{{ orion_agent_password }}\n"
    expect "Choose an option>"
    send "7\n"    
    expect "..."
    send "\n"
  args:
    executable: /usr/bin/expect


        "", 
        "Choose an option>7", 
        "", 
        "Agent device ID [F988BC59-EEC5-42E3-81BE-6E854E5A1000], Provisioned by [ch1-mntrw001], device ID [A7C87BAE-07A0-4D74-A3CE-D0810B04B347]", 
        "Press ENTER to continue…"




On Jan 15, 2019, at 9:10 AM, Freddie Eisa <fredd...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages