I use ansible to operate Windows, there are many problems!
As follows:
1. Use win_copy to copy the Shared directory or the middle file times of the network drive disk!
My Syntax is here ,
tasks:
- name: copy file
win_copy:
src: \\192.168.227.181\2.0.0\pys
dest: C:\tools
remote_src: True
The execution result:
ubuntu@xll-ubuntu:~$ ansible-playbook /etc/ansible/test.yml -vvv
ansible-playbook 2.4.3.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/ubuntu/.local/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
Using /etc/ansible/ansible.cfg as config file
Parsed /etc/ansible/hosts inventory source with ini plugin
PLAYBOOK: test.yml ********************************************************************************************************************************************************************************************
1 plays in /etc/ansible/test.yml
PLAY [dbServer] ***********************************************************************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************************************************************
Using module file /home/ubuntu/.local/lib/python2.7/site-packages/ansible/modules/windows/setup.ps1
<192.168.227.196> ESTABLISH WINRM CONNECTION FOR USER: administrator on PORT 5986 TO 192.168.227.196
EXEC (via pipeline wrapper)
ok: [192.168.227.196]
META: ran handlers
TASK [拷贝文件 到目标服务器上] *******************************************************************************************************************************************************************************************
task path: /etc/ansible/test.yml:4
Using module file /home/ubuntu/.local/lib/python2.7/site-packages/ansible/modules/windows/win_copy.ps1
<192.168.227.196> ESTABLISH WINRM CONNECTION FOR USER: administrator on PORT 5986 TO 192.168.227.196
EXEC (via pipeline wrapper)
fatal: [192.168.227.196]: FAILED! => {
"changed": false,
"dest": "C:\\tools",
"module_stderr": "Exception calling \"Run\" with \"1\" argument(s): \"Exception calling \"Invoke\" with \r\n\"0\" argument(s): \"The running command stopped because the preference variable \"\r\nErrorActionPreference\" or common parameter is set to Stop: 拒绝访问。\"\"\r\nAt line:47 char:5\r\n+ $output = $entrypoint.Run($payload)\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE \r\n xception\r\n + FullyQualifiedErrorId : ScriptMethodRuntimeException\r\n \r\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1,
"src": "\\\\192.168.227.181\\2.0.0\\pys"
}
to retry, use: --limit @/etc/ansible/test.retry
PLAY RECAP ****************************************************************************************************************************************************************************************************
192.168.227.196 : ok=1 changed=0 unreachable=0 failed=1
2. It is not possible to call python script replication through win_command, without error messages.(it's okay to do python on Windows)
This is failing because of the reasons I explained in your other question https://groups.google.com/forum/#!topic/ansible-project/Jz9ByKAJzS0. In short you should look at using become on your tasks to bypass the WinRM limitations. Also Ansible can execute Python scripts, I'm not sure why you are saying it has error messages but the rc is 0 and there is nothing on the stderr so that looks like it ran correctly.
- win_copy:
src: \\192.168.20.13\WuhanTeam\100_test
dest: C:\tools
become: yes
become_method: runas
become_flags: logon_type=new_credentials logon_flags=netcredentials_only
vars:
ansible_become_user: xie11
ansible_become_pass: 111111
- win_shell: |
$username = 'xie11'
$password = '111111'
$sec_password = ConvertTo-SecureString -String $password -AsPlainText -Force
$credentials = New-Object -TypeName PSCredential -ArgumentList $username, $sec_password
New-PSDrive -Name temp_path -PSProvider FileSystem -Root '\\192.168.20.13\WuhanTeam' -Credential $credential -Scope Script
Copy-Item -Path temp_path:\100_test -DestinationPath C:\tools
Thank you very much for your reply. I tried to use win-shell, but there was a syntax error!
Because I can't understand this meaning, please help to see!
As follows:
- hosts: dbServer
tasks:
- name: shell
- win_shell:
$username: 'xie11'
$password: '111111'
$sec_password: ConvertTo-SecureString -String $password -AsPlainText -Force
$credentials: New-Object -TypeName PSCredential -ArgumentList $username, $sec_password
New-PSDrive -Name temp_path -PSProvider FileSystem -Root '\\192.168.20.13\WuhanTeam' -Credential $credentials -Scope Script
Copy-Item -Path temp_path:\100_test -DestinationPath C:\tools
- name: copy file
win_copy:
src: \\192.168.20.13\WuhanTeam\100_test
dest: D:\tools
remote_src: True
You pretty much need to copy the win_shell task as it was (with any credential or path changes you need). You also don't need the win_copy tasks as the win_shell task will do that for you, I only provided that example to show you how it is easier to use become when 2.5 comes out.
You pretty much need to copy the win_shell task as it was (with any credential or path changes you need). You also don't need the win_copy tasks as the win_shell task will do that for you, I only provided that example to show you how it is easier to use become when 2.5 comes out.
You pretty much need to copy the win_shell task as it was (with any credential or path changes you need). You also don't need the win_copy tasks as the win_shell task will do that for you, I only provided that example to show you how it is easier to use become when 2.5 comes out.