从Ansible下载Windows Server 2012 R2和AWS S3 [英] Windows Server 2012 R2 and AWS S3 Download from Ansible

查看:270
本文介绍了从Ansible下载Windows Server 2012 R2和AWS S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从具有IAM Role for EC2的AWS S3下载一些文件,但Ansible出现错误.其他Ansible win_ *模块效果很好.

I'm trying to download some files from AWS S3 with IAM Role for EC2 but Ansible is getting an error. Other Ansible win_* modules works great.

Windows Server具有Python2和Python3,以及boto和boto3模块. Cmd正在响应python命令.执行时会打开Python3.在打开Python3时,我还测试了"import boto"命令,以确保已安装该模块.

Windows Server has Python2 and Python3, and also boto and boto3 modules. Cmd is responding to python command. It opens Python3 when it is executed. I also tested the 'import boto' command when the Python3 is opened to be sure that module is installed.

Ansible Playbook的配置如下:

Ansible Playbook is configured like:

- name: test s3 module
  hosts: windows
  tasks:
    - name: get s3 file
      aws_s3:
        bucket: drktests3
        object: /test
        dest: C:\tests3.txt
        mode: get

当我运行此配置时,输出如下:

When i run this configuration, the output is like that:

root@ip-172-31-22-4:/etc/ansible/playbooks# ansible-playbook s3test

PLAY [test s3 module] *******************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************
ok: [38.210.201.10]

TASK [get s3 file] **********************************************************************************************************************************************
 [WARNING]: FATAL ERROR DURING FILE TRANSFER:

fatal: [38.210.201.10]: FAILED! => {"msg": "winrm send_input failed; \nstdout: Unable to initialize device PRN\r\nUnable to initialize device PRN\r\nUnable to initialize device PRN\r\n\nstderr ANSIBALLZ_WRAPPER : The term 'ANSIBALLZ_WRAPPER' is not recognized as the name \r\nof a cmdlet, function, script file, or operable program. Check the spelling of \r\nthe name, or if a path was included, verify that the path is correct and try \r\nagain.\r\nAt line:1 char:1\r\n+ ANSIBALLZ_WRAPPER = True # For test-module script to tell this is a \r\nANSIBALLZ_WR ...\r\n+ ~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : ObjectNotFound: (ANSIBALLZ_WRAPPER:String) [], C \r\n   ommandNotFoundException\r\n    + FullyQualifiedErrorId : 

如果我将hosts值更改为localhost,则该脚本可在主服务器(Linux Ubuntu)上运行.为什么Ansible无法在Windows服务器上执行python代码?

The same script works on the Master server(Linux Ubuntu) if i change the hosts value to localhost. Why Ansible cannot execute the python code on the Windows server?

推荐答案

我发现

我可以运行Python模块吗? 否,WinRM连接协议设置为使用PowerShell模块,因此Python模块将无法使用.绕过此问题的一种方法是使用delegate_to:localhost在Ansible控制器上运行Python模块.如果在玩书期间需要联系外部服务并且没有可用的等效Windows模块,这将很有用.

Can I run Python modules? No, the WinRM connection protocol is set to use PowerShell modules, so Python modules will not work. A way to bypass this issue to use delegate_to: localhost to run a Python module on the Ansible controller. This is useful if during a playbook, an external service needs to be contacted and there is no equivalent Windows module available.

因此,如果要执行此过程,则必须解决该问题.

So if you want to do such a process, you have to workaround the problem.

我通过Ansible Documentation提供的建议解决了这个问题.

I solved it with suggestion that Ansible Documentation gives.

- name: test s3 module
  hosts: windows
  tasks:
    - name: get s3 file
      aws_s3:
        bucket: bucketname
        object: /filename.jpg
        dest: /etc/ansible/playbooks/test.jpg
        mode: get
      delegate_to: localhost

    - name: copy to win server
      win_copy:
        src: /etc/ansible/playbooks/test.jpg
        dest: C:/test.jpg

使用这些示例代码时,首先,您要使用委托_to将文件下载到Master Ansible服务器.然后将文件复制到Windows主机.

When you use these sample codes, firstly you are downloading the files to Master Ansible server with delegate_to. And after then that you are copying the files to Windows host.

这篇关于从Ansible下载Windows Server 2012 R2和AWS S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆