0

Context: I am working on a database project, I have a central server (linux) that has to ssh to a db server (linux) and run commands. The thing is that the database commands can only run from a specific directory.

I am using the shell module

So for instance, in my playbook I have this line: shell: ssh dbadmin@dbserver001 cd sqllib/bin/ ; ls

By the time the ls part runs, the terminal has already returned to the central server and its showing me the directory before I ran the ssh command (I want it to ls from the sqllib/bin/ directory and not the central server). I also tried replacing the ; with && and the same thing occurs.

Note that using ls directly after the ssh command works (shell: ssh dbadmin@dbserver001 ls) but I have to use cd first in order to get to the proper folder to run the database commands.

Is there a way to force it to stay in the ssh'ed directory? Otherwise it will be impossible to complete my project.

NewbChewbCS
  • 67
  • 2
  • 8
  • 1
    You need more quotes. `ssh dbadmin@dbserver001 'cd sqllib/bin && ls'`, so the `ls` is _an argument to ssh_, not a separate command that only runs after ssh exited. – Charles Duffy Sep 21 '21 at 15:49
  • 1
    BTW, I don't see anything in your question as currently posed that's `ansible`-specific. Once you have a `shell:` block, everything is passed to a shell where it's processed in a not-at-all-ansible-specific way. – Charles Duffy Sep 21 '21 at 15:51

0 Answers0