doina

一个小菜鸟运维工程师.

Ansible win_get_url 模块

可以从http,https,ftp下载资源.

参数 选项 作用
dest 必需,文件保存的位置
force no 文件不存在或者目标比本地文件行才进行下载
yes 默认,始终下载该文件
force_basic_auth no 默认,使用Microsoft的WebClient来处理身份验证
yes 在初始请求上添加基本身份验证标头
headers 将自定义HTTP标头添加到请求(作为字典)
proxy_url 代理服务器地址
proxy_username 代理服务器账号
proxy_password 代理服务器密码
timeout 超时时间,默认10s
url 必需,下载的文件的完整URL
url_username 认证用户
url_password 认证密码
use_proxy no 将不使用代理,即使在目标主机上的环境变量中定义了代理
yes 默认
validate_certs no 则不会验证SSL证书
yes 默认,验证SSL证书

模块使用

ansible方式

#http下载
[root@squid win_get_url]# ansible windows -m win_get_url -a "url=http://download.baiyongjie.com/linux/jumpserver/luna.tar.gz  dest=c:/tools/luna.tar.gz"   
10.241.0.4 | SUCCESS => {
    "changed": true, 
    "dest": "c:/tools/luna.tar.gz", 
    "msg": "OK", 
    "status_code": 200, 
    "url": "http://download.baiyongjie.com/linux/jumpserver/luna.tar.gz", 
    "win_get_url": {
        "dest": "c:/tools/luna.tar.gz", 
        "url": "http://download.baiyongjie.com/linux/jumpserver/luna.tar.gz"
    }
}

#ftp下载
[root@squid win_get_url]# ansible windows -m win_get_url -a "url=ftp://ftp.address.com/win_get_url/winGetUrl.txt  dest=c:/tools/winGetUrl.txt url_username=ftp_username url_password=ftp_password"
10.241.0.4 | SUCCESS => {
    "changed": true, 
    "dest": "c:/tools/winGetUrl.txt", 
    "msg": "OK", 
    "status_code": 200, 
    "url": "ftp://ftp.address.com/win_get_url/winGetUrl.txt", 
    "win_get_url": {
        "dest": "c:/tools/winGetUrl.txt", 
        "url": "ftp://ftp.address.com/win_get_url/winGetUrl.txt"
    }
}

playbook方式

#编写playbook
[root@squid win_get_url]# cat win_get_url.yaml 
---
- hosts: windows
  tasks:
  - name: download for http
    win_get_url:
      url: http://download.baiyongjie.com/linux/jumpserver/luna.tar.gz
      dest: c:/tools/luna.tar.gz

  - name: download for ftp
    win_get_url:
      url: ftp://ftp.address.com/win_get_url/winGetUrl.txt
      dest: c:/tools/winGetUrl.txt
      url_username: ftp_username
      url_password: ftp_password

#执行playbook
[root@squid win_get_url]# ansible-playbook win_get_url.yaml 

PLAY [windows] *********************************************************************************************

TASK [download for http] *********************************************************************************************
changed: [10.241.0.4]

TASK [download for ftp] *********************************************************************************************
changed: [10.241.0.4]

PLAY RECAP *********************************************************************************************
10.241.0.4                 : ok=2    changed=2    unreachable=0    failed=0  
点赞

发表评论

邮箱地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据