Search code examples
laravelbashstdoutstdinlaravel-envoy

Laravel Envoy to SSH into bastion server, then, SSH into individual private web servers, stdout is split into new lines


Our infrastructure/challenges are interesting, and I'm not finding anything too relevant online or on other SO questions.

Our build server is in a different VPC to our web servers, which are private. So build > web server isn't possible. I'm working locally with two VirtualBox VMs for proof of concept, no issues there. All works ok locally, using the two VMs.

Our deployments will be build > bastion > webserver.

I'm working on some Envoy scripts which will be trigged by GitLab's CI, which:

  • SSH into our build server
  • run envoy run deploy:code --arg1=a --arg2=b --arg3=c
  • envoy then SSH's into our bastion server
  • runs another script (Envoy eventually deploy.sh for now) to deploy code to our private web servers

VM1 Envoy.blade.php:

@task('deploy:code', ['on' => 'web'])
    ssh [email protected] -p 22 -tt
    /home/ubuntu/deploy.sh
@endtask

VM2 deploy.sh:

$ cat deploy.sh
echo "hello!"

Localhost command:

 envoy run deploy:code --a=a --b=b --c=c

output:

[[email protected] -p 10022]: /home/ubuntu/deploy.sh
[[email protected] -p 10022]: Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-193-generic x86_64)
[[email protected] -p 10022]: * Documentation:  https://help.ubuntu.com
[[email protected] -p 10022]: * Management:     https://landscape.canonical.com
[[email protected] -p 10022]: * Support:        https://ubuntu.com/advantage
[[email protected] -p 10022]: 105 packages can be updated.
[[email protected] -p 10022]: 86 updates are security updates.
[[email protected] -p 10022]: New release '18.04.5 LTS' available.
[[email protected] -p 10022]: Run 'do-release-upgrade' to upgrade to it.
[[email protected] -p 10022]: Last login: Fri Aug 27 15:51:11 2021 from 10.0.2.15
[[email protected] -p 10022]: ubuntu@ubuntu:~$
[[email protected] -p 10022]: ubuntu@ubuntu:~$ /h
[[email protected] -p 10022]: ome
[[email protected] -p 10022]: /ub
[[email protected] -p 10022]: un
[[email protected] -p 10022]: tu/
[[email protected] -p 10022]: depl
[[email protected] -p 10022]: oy.
[[email protected] -p 10022]: sh
[[email protected] -p 10022]: hello!
[[email protected] -p 10022]: ubuntu@ubuntu:~$

Can anyone suggest ways I can not have the output split over many lines, and instead just echo hello! after the welcome message/MOTD, and/or not have the output over many lines?


Solution

  • Fresh Monday morning eyes led me here:

    https://unix.stackexchange.com/questions/572412/when-running-local-script-on-remote-server-via-multiple-ssh-script-is-split-int

    replacing

    ssh [email protected] -p 22 -tt
    

    with

    ssh [email protected] -p 22 -t
    

    caused:

    Pseudo-terminal will not be allocated because stdin is not a terminal.

    A cheeky search later, suggested changing -t to -T

    https://appuals.com/fix-pseudo-terminal-will-not-be-allocated-because-stdin-is-not-a-terminal/

    ssh [email protected] -p 22 -T
    

    did the trick

    [[email protected] -p 10022]: Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-193-generic x86_64)
    [[email protected] -p 10022]: * Documentation:  https://help.ubuntu.com
    [[email protected] -p 10022]: * Management:     https://landscape.canonical.com
    [[email protected] -p 10022]: * Support:        https://ubuntu.com/advantage
    [[email protected] -p 10022]: 105 packages can be updated.
    [[email protected] -p 10022]: 86 updates are security updates.
    [[email protected] -p 10022]: New release '18.04.5 LTS' available.
    [[email protected] -p 10022]: Run 'do-release-upgrade' to upgrade to it.
    [[email protected] -p 10022]: hello!