ansible下载文件的多种方式

对于ansible来讲,下载文件是一个很重要的课题,这是build或者deploy的第一步,一般来说因为不一样项目的差别,可能咱们的代码包或者资源文件保存在于http,github,nexus,ftp,nas等等。git

从ansible server拷贝文件,前提是在使用ansible core

- name: Copy file with owner and permissions
  copy:
    src: /srv/myfiles/foo.conf
    dest: /etc/foo.conf
    owner: foo
    group: foo
    mode: '0644'

http文件下载,前提是http容许匿名用户下载

- name: download war file
  get_url:
    url: "{{ https_url }}/start.war"
    dest: /tmp
    mode: 0644
    force: yes
    validate_certs: no

github文件下载,前提是已经在github申请了token

- name: donwload docker rpm
  get_url:
    validate_certs: no
    url: https://github.com/raw/org_name/project/master/docker.rpm
    dest: /tmp/docker.rpm
    mode: 0755
    force: yes
    headers:
      Authorization: token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

若是想让文件下载到ansible master端,只要增长一条

delegate_to: localhostgithub

  • 一个完整的task,以下:
- name: donwload docker rpm
  get_url:
    validate_certs: no
    url: https://github.com/raw/org_name/project/master/docker.rpm
    dest: /tmp/docker.rpm
    mode: 0755
    force: yes
    headers:
      Authorization: token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  delegate_to: localhost
相关文章
相关标签/搜索