Question

how to create a ansible play book for below CLI prompt running in EC2 instance. i need to execute cli commands in sequence

Posted August 18, 2021 132 views
AnsibleUbuntu 18.04

[2021-08-18 10:55:59 admin@cmoulaniEMS: ~ ]# ssh -p 8122 admin@10.52.23.67
Password authentication
Password:

Insight

Insight Command Line Interface
Date: Wed Aug 18 10:56:08 IST 2021

find target instances
find target instances

    Target                 : TGMS
    Target Version         : ~
    Target Instance        : TGMS
    Target Instance Version: ~

    Target                 : TMS
    Target Version         : ~
    Target Instance        : TMS
    Target Instance Version: ~

    Target                 : PSX
    Target Version         : V14.00.00
    Target Instance        : cmoulanipsxmaster
    Target Instance Version: V14.00.00A019

    Target                 : PSX
    Target Version         : V14.00.00
    Target Instance        : vivekpsxslave
    Target Instance Version: V14.00.00R000

    Target                 : PSX
    Target Version         : V14.00.00
    Target Instance        : stipsxslave
    Target Instance Version: V14.00.00R000

    Target                 : PSX
    Target Version         : V14.00.00
    Target Instance        : stipsxmaster
    Target Instance Version: V14.00.00R000

    Target                 : PSX
    Target Version         : V14.00.00
    Target Instance        : cmoulanipsxslave
    Target Instance Version: V14.00.00A019

    Target                 : PSX
    Target Version         : V14.00.00
    Target Instance        : vivekpsxmaster
    Target Instance Version: V14.00.00R000

Result: Ok

s t i stipsxmaster
s t i stipsxmaster

Result: Ok

PSX:V14.00.00R000:stipsxmaster> update STIServerDevice STIServerDeviceId 123 MaxConnection 5
update STIServerDevice STIServerDeviceId 123 MaxConnection 5

Result: Ok
PSX:V14.00.00R000:stipsxmaster>

1 comment
  • my Requirement is needed a playbook to login below EC2 server take CLI output and write to CSV file

    [2021-08-18 10:55:59 admin@cmoulaniEMS: ~ ]# ssh -p 8122 admin@10.52.23.67
    Password authentication
    Password:

    Insight

    Insight Command Line Interface
    Date: Wed Aug 18 10:56:08 IST 2021

    find target instances
    find target instances

        Target                 : TGMS
        Target Version         : ~
        Target Instance        : TGMS
        Target Instance Version: ~
    
        Target                 : TMS
        Target Version         : ~
        Target Instance        : TMS
        Target Instance Version: ~
    
        Target                 : PSX
        Target Version         : V14.00.00
        Target Instance        : cmoulanipsxmaster
        Target Instance Version: V14.00.00A019
    
        Target                 : PSX
        Target Version         : V14.00.00
        Target Instance        : vivekpsxslave
        Target Instance Version: V14.00.00R000
    
        Target                 : PSX
        Target Version         : V14.00.00
        Target Instance        : stipsxslave
        Target Instance Version: V14.00.00R000
    
        Target                 : PSX
        Target Version         : V14.00.00
        Target Instance        : stipsxmaster
        Target Instance Version: V14.00.00R000
    
        Target                 : PSX
        Target Version         : V14.00.00
        Target Instance        : cmoulanipsxslave
        Target Instance Version: V14.00.00A019
    
        Target                 : PSX
        Target Version         : V14.00.00
        Target Instance        : vivekpsxmaster
        Target Instance Version: V14.00.00R000
    

    Result: Ok

    s t i stipsxmaster
    s t i stipsxmaster

    Result: Ok

    PSX:V14.00.00R000:stipsxmaster> update STIServerDevice STIServerDeviceId 123 MaxConnection 5
    update STIServerDevice STIServerDeviceId 123 MaxConnection 5

    Result: Ok
    PSX:V14.00.00R000:stipsxmaster>

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hello,

It is not very clear what commands exactly you need to run, but you could use the Ansible Shell module to run specific shell commands on your hosts.

Here is an example:

---
  - name: Shell Examples
    hosts: some_servers
    tasks:

    - name: Name of your task
      shell:
         " ls -lrt /var "
      register: lsout
      tags: lsout

    - debug: msg="{{displaylist.stdout_lines}}"

You can add more tasks depending on your needs.

Regards,
Bobby

  • basically, I have an application running in EC2 instance I need to perform the following steps

    1. login
    2. execute “ssh -p 8122 admin@10.52.23.67
    3. this will take me to the CLI prompt like below > execute command find target instances then output command shows like below > Target : PSX Target Version : V14.00.00 Target Instance : cmoulanipsxmaster Target Instance Version: V14.00.00A019

    I need to come out of the CLI prompt with the exit command and the output of the above command I need to write into CSV FILE.