Ansible Module - ARCHIVING

CodingDaddy·2022년 3월 19일
0

Ansible -Study

목록 보기
9/11
post-thumbnail

remote_src: yes → src 파일이 원격지(remote)에 있는 파일일 때 설정

Create a playbook ~/playbooks/zip.yml to make a zip archive opt.zip of /opt directory on web1 node and save it under /root directory on web1 node itself.

- hosts: web1
  tasks:
  - archive:
      path: /opt
      dest: /root/opt.zip
      format: zip

On Ansible controller (src: local), we have a zip archive local.zip. extract its contents on web1 under /tmp directory

- hosts: web1
  tasks:
  - unarchive:
      src: local.zip
      dest: /tmp

On web1 node(src: remote) we have an archive data.tar.gz under /root directory, extract it under /srv directory by developing a playbook.

data.tar.gz archive is removed after that

- hosts: web1
  tasks:
  - unarchive:
      src: /root/data.tar.gz
      dest: /src
      remote_src: yes
 
  - file:
      path: /root/data.tar.gz
      state: absent

File-state 더 알아보기

download and extract the https://github.com/Hello-World/archive/master.zip zip archive under /root directory on the web1 node.

- hosts: web1
  tasks:
  - unarchive:
      src: https://github.com/Hello-World/archive/master.zip
      dest: /root
      remote_src: yes

three files are on web1 node /root/file1.txt, /usr/local/share/file2.txt and /var/log/lastlog. Create a bz2 archive of all these files and save it under /root directory, name the archive as files.tar.bz2

- hosts: web1
  tasks:
  - archive:
      path:
      - /root/file1.txt      
      - /usr/local/share/file2.txt      
      - /var/log/lastlog
      dest: /root/files.tar.bz2
      format: bz2

a. Install nginx package and start/enable its service.

b. Extract /root/nginx.zip archive under /usr/share/nginx/html directory.

c. Inside /usr/share/nginx/html/index.html replace line This is sample html code with line This is Ansible lab.

- hosts: web1
  tasks:
  - yum:
      name: nginx
      state: present
      
  - service:
      name: nginx
      state: started
      enabled: yes

  - unarchive:
      src: /root/nginx.zip
      dest: /usr/share/nginx/html
      remote_src: yes
    
  - replace:
      path: /usr/share/nginx/html/index.html
      regexp: 'This is sample html code'
      replace: 'This is Ansible lab'
profile
Creative - DevOps in Korea

0개의 댓글