HP ILO textcons/vsp and continue working from there

685 views
Skip to first unread message

Sosys

unread,
Jul 6, 2018, 2:28:08 AM7/6/18
to ansible...@googlegroups.com
Hi,

So i got this problem and see if ansible can help to fit in.

i got HP server that is only accessible from ILO.
Connecting to ILO is not an issue, because it's a ssh channel.

From here, we can issue command like textcons, where it will  go to the OS level for login.

i can issue textcons command using raw module (as hpilo does not support python), but how do i enter the OS login and password ?

FYI, the OS does not have IP configured, so im trying to go in and assign IP to gain access.

Thanks

Benny Kusman

unread,
Jul 6, 2018, 2:38:08 AM7/6/18
to Ansible Project
To elaborate, once connected to ilo, i will perform the following:
1. issue command: textcons
2. then the OS login screen appear, i will key in the userid and password
3. perform some shell command on the OS

Kai Stian Olstad

unread,
Jul 6, 2018, 2:51:58 AM7/6/18
to ansible...@googlegroups.com
On 06.07.2018 08:27, Sosys wrote:
> Hi,
>
>
> So i got this problem and see if ansible can help to fit in.
>
>
> i got HP server that is only accessible from ILO.
> Connecting to ILO is not an issue, because it's a ssh channel.
>
>
> From here, we can issue command like *textcons*, where it will go to
> the
> OS level for login.
>
>
> i can issue textcons command using raw module (as hpilo does not
> support
> python), but how do i enter the OS login and password ?
>
>
> FYI, the OS does not have IP configured, so im trying to go in and
> assign
> IP to gain access.

You can do this with the expect module.

--
Kai Stian Olstad

Sosys

unread,
Jul 6, 2018, 3:26:03 AM7/6/18
to ansible...@googlegroups.com
Unfortunately, expect is not installed yet.

--
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/52406dd8342a5fa468ee879ca72bf652%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Sosys

unread,
Jul 6, 2018, 3:28:25 AM7/6/18
to ansible...@googlegroups.com
Probably i could try to send multiple "enter" command
i tried sending "\n" after each command, but seems not "consumed".

anyone knows how to send "enter" command in a single string ?
for example, this is what i tried to do:

tasks:
  - name: sending all the required command
    raw: "textcons\\nroot\\nmypassword\\necho date"

 

Kai Stian Olstad

unread,
Jul 6, 2018, 4:15:35 AM7/6/18
to ansible...@googlegroups.com
On 06.07.2018 09:25, Sosys wrote:
> Unfortunately, expect is not installed yet.

You don't need expect on the remote host, only on the Ansible
controller(the machine running ansible command).

--
Kai Stian Olstad

Sosys

unread,
Jul 6, 2018, 5:08:40 AM7/6/18
to ansible...@googlegroups.com
the hpilo does not come with pexcept. It will through HPILO error.

  tasks:
    - name: login into ILO and set textcons
      raw: textcons
      expect:
        command: textcons
        reponses:
          'hostname login:': 'root'
          'Password:': 'password'
        echo: yes
        timeout: 20

FAILED! => {"changed": false, "module_stderr": "", "module_stdout": "/bin/sh -c '/usr/bin/python && sleep 0'\r", "msg": "MODULE FAILURE", "rc": 0}



What i was thinking is:
1. using raw module to execute "textcons". This is working and will go into the console OS (much like xen using xl console vmname or virsh console vmname)
2. From the above, the ansible is something expecting some response back before going to next task. How do i tell ansible to continue to "login into the server using the expect"


Thanks!


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

Kai Stian Olstad

unread,
Jul 6, 2018, 5:37:22 AM7/6/18
to ansible...@googlegroups.com
On 06.07.2018 11:08, Sosys wrote:
> the hpilo does not come with pexcept. It will through HPILO error.
>
>
> tasks:
> - name: login into ILO and set textcons
> raw: textcons
> expect:
> command: textcons
> reponses:
> 'hostname login:': 'root'
> 'Password:': 'password'
> echo: yes
> timeout: 20
>
>
> FAILED! => {"changed": false, "module_stderr": "", "module_stdout":
> "/bin/sh -c '/usr/bin/python && sleep 0'\r", "msg": "MODULE FAILURE",
> "rc":
> 0}
>
>
> What i was thinking is:
> 1. using raw module to execute "textcons". This is *working *and will
> go
> into the console OS (much like xen using xl console vmname or virsh
> console
> vmname)
> 2. From the above, the ansible is something expecting some response
> back
> before going to next task. How do i tell ansible to continue to "login
> into
> the server using the expect"

I'm pretty sure raw module would be a dead end, and expect is the way to
go.

You need to use expect on ssh, so your playbook should have hosts:
localhost or set the delegate_to: localhost on the task.


- name: login into ILO and set textcons
expect:
command: ssh <user>@<hp ilo>
reponses:
'some ssh prompt': 'the answer'
'some prompt for when textcons need to be typed': textcons
'hostname login:': 'root'
'Password:': 'password'
delegate_to: localhost

If you show a complete output of a manual run from ssh to the end I can
always help with the expect if you like.


--
Kai Stian Olstad

Sosys

unread,
Jul 6, 2018, 5:51:12 AM7/6/18
to ansible...@googlegroups.com
Hi Kai,

Thanks for the help.

so this is the rundown:
1. After executing the ssh login command, it will produce: root@servername's password:
Question: how do escape the quote character in the responses ? can i instead use * ?
2. then it will login into the ILO with this output:
User:root logged-in to servername
iLO Advanced 2.55 at  Aug 16 2017
Server Name: hostname
Server Power: On
</>hpiLO-> 

3. i will need to type either "textcons" or "vsp" to reach the OS console
4. once in the OS console, it will be pretty much like normal linux login prompt
servername login:
Password:

Thanks!

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

Sosys

unread,
Jul 6, 2018, 6:00:50 AM7/6/18
to ansible...@googlegroups.com
On top of this, pexpect has been installed
[root@localhost ~]# pip install pexpect
Requirement already satisfied: pexpect in /usr/lib/python2.7/site-packages (4.5.0)

But upon running it, it keep saying:
FAILED! => {"changed": false, "msg": "The pexpect python module is required"}

Sosys

unread,
Jul 6, 2018, 6:07:45 AM7/6/18
to ansible...@googlegroups.com
OK, apparently i need " ptyprocess " too, but not written in the expect module information.

Kai Stian Olstad

unread,
Jul 6, 2018, 6:14:37 AM7/6/18
to ansible...@googlegroups.com
On 06.07.2018 11:50, Sosys wrote:
> Hi Kai,
>
>
> Thanks for the help.
>
>
> so this is the rundown:
> 1. After executing the ssh login command, it will produce:
> *root@servername's
> password:*
> *Question: *how do escape the quote character in the responses ? can i
> instead use * ?

You only need to check for the last bit as long as there are no conflict
aka the string appears multiple times in the output.
Expect uses regexp and . (dot) is any character.


> 2. then it will login into the ILO with this output:
>
>
>> User:root logged-in to servername
>> iLO Advanced 2.55 at Aug 16 2017
>> Server Name: hostname
>> Server Power: On
>> </>hpiLO->
>
>
>
>
> 3. i will need to type either "textcons" or "vsp" to reach the OS
> console
> 4. once in the OS console, it will be pretty much like normal linux
> login
> prompt
>
>
>> servername login:
>> Password:


So this should be close

- name: login into ILO and set textcons
expect:
command: ssh <user>@<hp ilo>
reponses:
password: <the ssh pass>
hpiLO->: textcons
login: <username>
Password: <the OS pass>
<os prompt>:
- <command 1>
- <command 2>
- <command 3>
- <command 4>
delegate_to: localhost


--
Kai Stian Olstad

Sosys

unread,
Jul 6, 2018, 6:33:01 AM7/6/18
to ansible...@googlegroups.com
HI Kai,

Thanks a lot.
it did work!

now, managed to get to the server from the ILO as per expectation.
But, wondering 2 things:
1. the task always returned failed, with rc:255
2. it has reached the server OS (since password has been given), but is there any way to continue working on the server ? that means, once logged in, i need to perform some shell command.



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

Kai Stian Olstad

unread,
Jul 6, 2018, 6:47:14 AM7/6/18
to ansible...@googlegroups.com
On 06.07.2018 12:32, Sosys wrote:
> HI Kai,
>
>
> Thanks a lot.
> it did work!
>
>
> now, managed to get to the server from the ILO as per expectation.
> But, wondering 2 things:
> 1. the task always returned failed, with rc:255
> 2. it has reached the server OS (since password has been given), but is
> there any way to continue working on the server ? that means, once
> logged
> in, i need to perform some shell command.

You would need to use the same expect, that is what is illustrated with

<os prompt>:
- <command 1>
- <command 2>
- <command 3>
- <command 4>

Just put in you OS prompt and the you can run as many commands you would
like.

To not get rc 255 you need to exit all level, exit in OS and iLO until
ssh terminate cleanly.

In expect module you can only have one uniq prompt, if you have many
answers/responses they must be a list under that answer/prompt.


--
Kai Stian Olstad

Sosys

unread,
Jul 8, 2018, 12:13:28 AM7/8/18
to ansible...@googlegroups.com
Hi Kai,

Thanks so much for guiding through. It seems to work. 

        <os prompt>:
            - <command 1>
            - <command 2>
            - <command 3>
            - <command 4>

Just to understand on your this statement:

In expect module you can only have one uniq prompt, if you have many 
answers/responses they must be a list under that answer/prompt.

Does the list of answer and responses must match sequence by sequence ? 
Or it does not matter as long as prompt questions are unique ?

Thank you so much. this information shall be provided in the ansible doc too :)

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

Kai Stian Olstad

unread,
Jul 11, 2018, 5:40:00 AM7/11/18
to ansible...@googlegroups.com
On 08.07.2018 06:13, Sosys wrote:
> Just to understand on your this statement:
>
>
> In expect module you can only have one uniq prompt, if you have many
>> answers/responses they must be a list under that answer/prompt.
>
>
> Does the list of answer and responses must match sequence by sequence ?
> Or it does not matter as long as *prompt* questions are unique ?

Dict in Python/Ansible is unordered so the order of the prompt/question
doesn't matter, and they must be uniq, if not it will fail.
But the answers is a list and the order matter, the first time expect
sees the prompt is with use the first element in the list, the second
time it sees the prompt is will use the second element in the list and
so on.


> Thank you so much. this information shall be provided in the ansible
> doc
> too :)

Yes, but no one has stepped up, feel free to do so it if you want.


--
Kai Stian Olstad

Sosys

unread,
Jul 13, 2018, 12:25:56 AM7/13/18
to ansible...@googlegroups.com
Hi Kai,

much appreciated!
thanks so much!




--
Kai Stian Olstad

--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/78490cd3fba0f008fd03fb8eba1c8a80%40olstad.com.
Reply all
Reply to author
Forward
0 new messages