[ansible-project] Re: Best way to run Python scripts against Managed Cygwin nodes

2018-05-15 Thread Ab Generette
Since I'm no longer going to try and run this via a script, I'd like to 
close this topic and start another one.

On Monday, May 14, 2018 at 2:52:55 PM UTC-4, Ab Generette wrote:
>
> I have a CentOS7 control server from which I am trying to manage a few 
> Server2012/Cygwin nodes.  Those latter nodes have Cygwin setup such that 
> its sshd component is installed and running (I'm able to successfully ssh 
> to the targets).
>
> My ~/.ansible.cfg is the active one and this file contains 
>
> inventory = ~/playbooks/inv/hosts
>
>
> The relevant entries in that inventory file for target that I've focused 
> on are (note: the "abc_*" variables referenced in the inventory file are 
> stored in a vault file that's pulled in, of course, at run time):
>
> [abc_windows]
> wrk04 ansible_host=< target's IP >
>
> [abc_windows:vars]
> ansible_user = "{{ abc_win_ansible_user }}"
> ansible_password = "{{ abc_win_ansible_pwd }}"
> ansible_port = 5986
> ansible_winrm_transport = ntlm
> ansible_connection = winrm
> ansible_winrm_server_cert_validation = ignore
>
>
> A GUI based installer for my company's software drops in a bunch of files 
> that include the ones referenced in the python_exec, working_dir, 
> sharefile_script, and confl_script variables, below.
>
> Now, among other things, I've been trying to automate the task of running 
> a couple of Python scripts against each of the managed nodes.  The 
> playbook, template, and shell script, pasted below, seek to accomplish that 
> end.  At the very end of this posting, you can see the output that I get, 
> when I run the playbook.  The "/tmp/sharefiles_confl.log" file is never 
> created and the scripts never get run, as far as I can tell.
>
>
> [agenerette@build playbooks]$ cat sharefiles_confluence.yml
> ---
> - hosts: "{{ targets }}"
>   user: "{{ admin }}"
>   gather_facts: yes
>
>   vars:
> python_exec: /cygdrive/c/Python27/python.exe
> working_dir: /cygdrive/c/abc/run/ab
>
> sharefile_script: /cygdrive/c/abc/run/ab/tests/sharefile_api_test.py
> confl_script: /cygdrive/c/abc/run/ab/tests/confluence_api_test.py
>
>   tasks:
> - name: Place test script
>   win_template:
> src: templates/sharefiles_confluence.template
> dest: ~/sharefiles_confluence.sh
> owner: "{{ admin }}"
> mode: u+rwx,g+rwx
>   ignore_errors: yes
>
> - name: Do a test run of Sharefiles and Confluence API scripts...
>   raw: ~/sharefiles_confluence.sh
>   ignore_errors: yes
>   register: result
> - debug: var=result
>
> 
> 
> NOTE: the "my_*" variables referenced in the following template are also 
> stored in the vault file that's pulled in, of course, at run time:
>
> [agenerette@build playbooks]$ cat templates/sharefiles_confluence.template
> #!/bin/bash
>
> export ldap_user="{{ my_ldap_user }}"
> export ldap_pass="{{ my_ldap_pass }}"
> export ldap_reg_code="null"
> export gdoc_pass="{{ my_gdoc_pass }}"
> export share_user="{{ my_sharefiles_user }}"
> export share_pass="{{ my_sharefiles_pass }}"
> export wiki_user="{{ my_ldap_user }}"
> export wiki_pass="{{ my_ldap_pass }}"
>
> echo $ldap_user > /tmp/sharefiles_confl.log
>
> "{{ python_exec }} {{ sharefile_script }} && {{ python_exec }} {{ 
> confl_script }}" >> /tmp/sharefiles_confl.log
>
>
>
> And here's a sample run, with output:
>
> [agenerette@buildplaybooks]$ ansible-playbook -e admin=agenerette -e 
> targets=wrk04 -e @~/.ansible/secure.yml sharefiles_confluence.yml 
> --ask-vault-pass
> ...
>
> PLAY [wrk04] *
>
> TASK [Place test script] 
> ***
> ok: [wrk04]
>
> TASK [Do a test run of Sharefiles and Confluence API scripts...] 
> ***
> changed: [wrk04]
>
> TASK [debug] 
> ***
> ok: [wrk04] => {
> "result": {
> "changed": true,
> "rc": 0,
> "stderr": "",
> "stdout": "",
> "stdout_lines": []
> }
> }
>
> PLAY RECAP 
> *
> wrk04: ok=3changed=1unreachable=0failed=0
>
>

-- 
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/2fa90c7c-8207-4b64-9292-0ed6f857894c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Best way to run Python scripts against Managed Cygwin nodes

2018-05-14 Thread Jordan Borean
Hmm, looks like your host vars isn't matching which what I expect, it is 
actually connecting over SSH and not WinRM when your original post said you 
defined ansible_connection: winrm. Is there a reason why you are using 
SSH/Cygwin on Windows, we don't support it currently as a valid 
configuration because of issues/complications with the whole setup.

Thanks

Jordan

-- 
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/2cf723e3-3822-4fd2-9558-fe8cc15d6c56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Best way to run Python scripts against Managed Cygwin nodes

2018-05-14 Thread Ab Generette
Thanks, Jordan.  Ok, I believe I see what you mean.  I only went down this 
convoluted path involving the script and all, because of other problems 
that I ran into.

Changing that playbook to:

---
- hosts: "{{ targets }}"
  user: "{{ admin }}"
  gather_facts: yes

  vars:
python_exec: /cygdrive/c/Python27/python.exe
working_dir: /cygdrive/c/t3/run/ae

sharefile_script: /cygdrive/c/t3/run/ae/tests/sharefile_api_test.py
confl_script: /cygdrive/c/t3/run/ae/tests/confluence_api_test.py

  tasks:
- name: Do a test run of Sharefiles and Confluence API scripts...
  raw: "{{ item }}"
  with_items:
- "{{ sharefile_script }}"
- "{{ confl_script }}"
  environment:
ldap_user: "{{ my_ldap_user }}"
ldap_reg_code: "null"
ldap_pass: "{{ my_ldap_pass }}"
gdoc_pass: "{{ my_gdoc_pass }}"
share_user: "{{ my_sharefiles_user }}"
share_pass: "{{ my_sharefiles_pass }}"
wiki_username: "{{ my_ldap_user }}"
wiki_password: "{{ my_ldap_pass }}"
  ignore_errors: yes
  register: result
- debug: var=result


I get:

873320-wrk04-ia | FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Shared connection to 192.168.100.127 closed.\r\n",
"module_stdout": "C:\\Python27\\python.exe: can't open file 
'/home/agenerette/.ansible/tmp/ansible-tmp-1526330963.81-213142328853085/win_ping.py':
 
[Errno 2] No such file or directory\r\r\n",
"msg": "MODULE FAILURE"
}


On Monday, May 14, 2018 at 3:54:43 PM UTC-4, Jordan Borean wrote:
>
> I'm a bit confused, do you need to use Cygwin to run this script, 
> everything would be so much simpler if you ignored Cygwin and used 
> something like PowerShell or pure Python? For your current playbook there 
> are a few issues I see;
>
>- Windows modules, like win_template, do not support the mode/owner 
>options when it comes to files. Windows uses a more complex setup using 
>ACLs which don't map neatly with the traditional unix permissions
>- You are connecting over WinRM (not SSH in cygwin), unix-isms like ~/ 
>may work but not strictly Windows and may not work in all cases. The path 
>to ~/ is not necessarily the same path when you are in cygwin, e.g. it's 
>probably going to be a path in the user directory
>- The raw module invocation is expecting to be in a cygwin environment 
>as you are calling a bash script, you are actually in a PowerShell 
>environment and need to explicitly call C:\cygwin\bin\bash.exe (or 
> wherever 
>it is located) to execute the bash script in cygwin
>
> What I would do is get rid of the bash script and just execute the Python 
> scripts you have directly in Windows.
>
> Thanks
>
> Jordan
>

-- 
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/7bf3994e-2ec6-4d77-a076-2d975ce3cb53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Best way to run Python scripts against Managed Cygwin nodes

2018-05-14 Thread Jordan Borean
I'm a bit confused, do you need to use Cygwin to run this script, 
everything would be so much simpler if you ignored Cygwin and used 
something like PowerShell or pure Python? For your current playbook there 
are a few issues I see;

   - Windows modules, like win_template, do not support the mode/owner 
   options when it comes to files. Windows uses a more complex setup using 
   ACLs which don't map neatly with the traditional unix permissions
   - You are connecting over WinRM (not SSH in cygwin), unix-isms like ~/ 
   may work but not strictly Windows and may not work in all cases. The path 
   to ~/ is not necessarily the same path when you are in cygwin, e.g. it's 
   probably going to be a path in the user directory
   - The raw module invocation is expecting to be in a cygwin environment 
   as you are calling a bash script, you are actually in a PowerShell 
   environment and need to explicitly call C:\cygwin\bin\bash.exe (or wherever 
   it is located) to execute the bash script in cygwin

What I would do is get rid of the bash script and just execute the Python 
scripts you have directly in Windows.

Thanks

Jordan

-- 
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/ab16db93-b93d-446d-827d-73fc2277c05b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.