On 29.08.2018 12:21, julian.mitchellkr...@gmail.com wrote:
Fantastic.
So the box is running acme sbc.
Aim to achieve the following via AWX / Ansible:
***************# show platform cpu-load summary <------- the command to run
Total load:       11%
          CPU#00  14%
          CPU#01  8%

Load average: 2.86 3.00 3.00 2/281 7385

You have redacted the most important part the prompt.
Expect is petty easy, it looks for a string/text, when it sees that ecpect respond with a command and press enter. This string must be unique or else expect will type a command at the wrong place.
But if you do not have # anywhere else you can use that.


Playbook contents :

---
- name: Check CPU Load
  hosts: all
  connection: local
  gather_facts: yes


  tasks:

  - name: Get CPU Load
    expect:
      command: show platform cpu-load summary

The command is the ssh command you need to login.

So you should a provided the whole output above, staring from a Linux prompt above. Think of expect as a user that is typing the command manually. So need to start from prompt to now what is needed in responses bellow, because every keystroke you do expect has to do them also.


      responses:
        cpu

The responses part is where you have the question answer section, this is the string expect is waiting for and the command it should type.

So in your case we need to use the prompt/string # since you redacted the rest

  responses:
    '#': show platform cpu-load summary

So the # is the question/string/prompt and the part after colon is the command to run.
The quotes is needed if not # is taken as a comment.

If you would like to run more than one command per unique prompt they need to be in a list:

  responses:
    '#':
      - show platform cpu-load summary
      - show something else

You probably need to handle the password prompt in the responses too.

--
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+unsubscr...@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/15e941d59f450cab9124174c8b9f35e2%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to