Skip to main content

playbook-copy

Le module Copy : généralités, validate, backup, recurse

Objectif: copier des fichiers ou du contenu Equivalent de : scp

Paramètres:

  1. attributes: attributs du fichier
  2. backup: réalise une copie dotée avant la copie
  3. checksum: vérification contenu du fichier via hash
  4. content: dans le cas ou la source n'est pas un fichier mais une variables ou string
  5. decrypt: déchiffrement les fichier si ils sont vaultés

[script-copy]:

"create file test.txt"

- name: "nom du playbook"
hosts: all
become: yes
tasks:
- name: module copy
copy:
src: test.txt
dest: /tmp/test.txt
- name: copy directory folder
copy:
src: /home/mekoo/test.txt
dest: /tmp/mekoo

[script-remote_src]:

- name: "nom du playbook"
hosts: all
become: yes
tasks:
- name: remote src copy
copy:
src: /tmp/mekoo/
dest: /tmp/mekoo/
remote_src: yes

[script-combinaison]:

- name: "nom du playbook"
hosts: all
become: yes
vars:
mesfichiers:
- { source: "mekoo.txt", destination: "/tmp/monfichiermekoo.txt", mode: "0755", owner: "mekoo"}
- { source: "mekoo2.txt", destination: "/tmp/monfichiermekoo2.txt", mode: "0644", owner: "mekoo"}
tasks:
- name: remote src copy
copy:
src: "{{ item.source }}"
dest: " {{item.destination}} "
mode: " {{item.mode}} "
owner: " {{item.owner}} "
with_items:
- " {{ mesfichiers }} "

ansible-playbook -i 00_inventory.yml playbook.yml

[script-patterns]:

command: ansible-playbook -i 00_inventory.yml playbook.yml

#create file mekoo.txt && mekoo2.txt

- name: "nom du playbook"
hosts: all
become: yes
tasks:
- name: remote src copy
copy:
src: "{{ item.source }}"
dest: " {{item.destination}} "
with_fileglob:
- mekoo*
- text*

[script-backup-before-change]:

#create file mekoo.txt && mekoo2.txt

- name: "nom du playbook"
hosts: all
become: yes
tasks:
- name: remote src copy
copy:
src: "{{ item }}"
dest: /tmp/
backup: yes
with_fileglob:
- mekoo*

ansible-playbook -i 00_inventory.yml playbook.yml

LE MODULE FETCH : RECUPERER DES FICHIERS ET ASTUCES

[script-fetch-target-folder-ans-file-simple]:

- name: "nom du playbook"
hosts: all
become: yes
tasks:
- name: Fetch use
fetch:
src: /etc/hosts
dest: /tmp/

[script-fetch-target-folder-avec-flat]:

- name: "nom du playbook"
hosts: all
become: yes
tasks:
- name: Fetch use
fetch:
src: /etc/hosts
dest: /tmp/hosts_{{ ansible_hostname }}.txt

[script-fetch-target-folder-avec-flat]:

- name: "nom du playbook"
hosts: all
become: yes
tasks:
- name: Fetch use
fetch:
src: /etc/hosts
dest: /tmp/hosts_{{ ansible_hostname }}.txt
flat: yes

[script-pratique-nginx-copy]:

tuto-xavki

attention après installation nginx activer la lecture des fichiers (/etc/nginx/site-avaiables/) autoindex on; autoindex_exact_size: off;

  - name: "installation nginx"
hosts: all
connection: local
become: yes
tasks:
- name: Install nginx
apt:
name: nginx
state: present

- name: clean
file:
path: "{{item}} "
state: absent
with_fileglob:
- "/var/www/html/*.html"

- name: permission user
file:
path: "/var/www/html"
owner: root
recurse: yes
state: directory

- name: module copy
host: all
become: yes
tasks:
- name: fetch
fetch:
src: /etc/hosts
dest: /var/www/html/hosts_{{ ansible_hostname }}.txt
flat: yes

docs Mercvi à Xavki pour son travaille. xavki