Without looking too closely at your code/error I ran into what may be a 
related issue.  It's because the shell is not sourcing the profiles of the 
SSH user.  I had to update my shell command to source my bashrc and 
primarily my profile first before executing my command like so:

shell: . /path to home/.bashrc && . /path to profile/profile && [command to 
run here]

Hope that helps, it was a very hard journey to figure this out for my 
installation.

Kim

On Thursday, February 11, 2016 at 12:04:47 PM UTC-7, 
[email protected] wrote:
>
> Hello all,
>
> I am using ansible to deploy and provision some instances then runs a 
> python script at the very end. The python script uses the subprocess 
> module 
> <https://docs.python.org/2/library/subprocess.html#popen-constructor> to 
> call a sql script and generate flat text files. When I directly ssh into 
> the instances and run remotely, everything works. However when I use 
> ansible to call the python script it looks like commands don't get passed 
> to the Popen construct OR sqlplus is not installed??? Which is weird cause 
> it definitely is installed. This may be a more python oriented question but 
> since I only have the issue when using Ansible to run the python program... 
> I'm posting here. 
>
> Ansible: 
> ansible webservers -i inventory --vault-password-file ~/.vault_pass.txt -u 
> ec2-user -m command -a "python script.py chdir=dir/dir1/dir2"
>
> Python:
> connect_string=username/password@connectionObject
> sql_command=@sql_script.sql
>
> def run_sql_query(sql_command, connect_string):
>   """
>   Run sqlCommand and return query result and error Message
>   """
>   session = Popen(['sqlplus', '-S', connect_string], stdin=PIPE, 
> stdout=PIPE, stderr=PIPE)
>   session.stdin.write(sql_command)
>   return session.communicate()
>
> Error:
>   File "/usr/lib64/python2.7/subprocess.py", line 710, in __init__
>     errread, errwrite)
>   File "/usr/lib64/python2.7/subprocess.py", line 1335, in _execute_child
>     raise child_exception
> OSError: [Errno 2] No such file or directory
>
> A closer look shows that one of the following is happening:
>
> 1) /bin/bash: sqlplus: command not found
>  
> HOW???
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4a3b410b-bc4b-4eae-bce6-8f8da98ed391%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to