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
相關文章
相關標籤/搜索