# HP ILO textcons/vsp and continue working from there

**URL:** <https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971>\
**Category:** Ansible Project\
**Created:** [July 6, 2018, 6:27am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971 "2018-07-06T06:27:49Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 6, 2018, 6:27am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/1 "2018-07-06T06:27:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 6, 2018, 6:38am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/2 "2018-07-06T06:38:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 6, 2018, 6:51am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/3 "2018-07-06T06:51:46Z")

</div>

You can do this with the expect module.

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 6, 2018, 7:25am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/4 "2018-07-06T07:25:43Z")

</div>

Unfortunately, expect is not installed yet.

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 6, 2018, 7:28am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/5 "2018-07-06T07:28:05Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 6, 2018, 8:15am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/6 "2018-07-06T08:15:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 6, 2018, 9:08am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/7 "2018-07-06T09:08:21Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 6, 2018, 9:37am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/8 "2018-07-06T09:37:11Z")

</div>

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.

&nbsp;&nbsp;&nbsp;- name: login into ILO and set textcons  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: ssh \<user\>@\<hp ilo\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reponses:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'some ssh prompt': 'the answer'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'some prompt for when textcons need to be typed': textcons  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'hostname login:': 'root'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Password:': 'password'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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.

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 6, 2018, 9:50am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/9 "2018-07-06T09:50:52Z")

</div>

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

1. i will need to type either “textcons” or “vsp” to reach the OS console
2. once in the OS console, it will be pretty much like normal linux login prompt

> servername login:  
> Password:

Thanks!

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 6, 2018, 10:00am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/10 "2018-07-06T10:00:30Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 6, 2018, 10:07am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/11 "2018-07-06T10:07:21Z")

</div>

OK, apparently i need " ptyprocess " too, but not written in the expect module information.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 6, 2018, 10:14am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/12 "2018-07-06T10:14:29Z")

</div>

> 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

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

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 6, 2018, 10:32am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/13 "2018-07-06T10:32:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 6, 2018, 10:47am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/14 "2018-07-06T10:47:04Z")

</div>

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

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<os prompt\>:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- \<command 1\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- \<command 2\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- \<command 3\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- \<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.

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 8, 2018, 4:13am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/15 "2018-07-08T04:13:08Z")

</div>

Hi Kai,

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

:

- \<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 🙂

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 11, 2018, 9:39am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/16 "2018-07-11T09:39:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 13, 2018, 4:25am UTC](https://forum.ansible.com/t/hp-ilo-textcons-vsp-and-continue-working-from-there/27971/17 "2018-07-13T04:25:39Z")

</div>

Hi Kai,

much appreciated!  
thanks so much!
