Criando arquivos via ansible
---
- hosts: localhost
tasks:
- name: Creating an empty file
file:
path: "/etc/ansible/file01.txt" >>> CAMINHO DO ARQUIVO
state: touch
Criando arquivos via ansible
---
- hosts: localhost
tasks:
- name: Creating an empty file
file:
path: "/etc/ansible/file01.txt" >>> CAMINHO DO ARQUIVO
state: touch
Inserindo informações
---
- hosts: localhost
tasks:
- name: Creating a file with content
copy:
dest: "/etc/ansible/file01.txt"
content: |
line 01
line 02
lucas@lucas-VirtualBox:/etc/ansible$ cat file01.txt
line 01
line 02
lucas@lucas-VirtualBox:/etc/ansible$
---
- hosts: all
tasks:
- name: Create a new file with permissions
file:
path: "/your path"
state: touch
mode: 0755
owner: test
Criando multplos arquivos
root@lucas-VirtualBox:/etc/ansible/Linux-ansible# nano Multiplosfile.yaml
GNU nano 4.8 Multiplosfile.yaml
---
- hosts: localhost
tasks:
- name: Create multiple files
file:
path: "/etc/ansible/{{ item }}"
state: touch
with_items:
- test01.txt
- test02.txt
- test03.txt
- test04.txt
lucas@lucas-VirtualBox:/etc/ansible$ ls
ansible.cfg estudos_pdf hosts Linux-ansible PROJETO-ANSIBLE-JINJA2 show_run_192.168.1.99.txt test01.txt test03.txt
CONFIGS file01.txt JUNOS projects show_run_192.168.1.99.cfg TEMPLATES test02.txt test04.txt
Criando diretorio
---
- hosts: localhost
tasks:
- name: Creating a new directory
file:
path: "/etc/ansible/TESTE"
state: directory
lucas@lucas-VirtualBox:/etc/ansible$ ls
ansible.cfg estudos_pdf hosts Linux-ansible PROJETO-ANSIBLE-JINJA2 show_run_192.168.1.99.txt test01.txt test03.txt TESTE
CONFIGS file01.txt JUNOS projects show_run_192.168.1.99.cfg TEMPLATES test02.txt test04.txt
Removendo
GNU nano 4.8 remove.yaml
---
- hosts: localhost
tasks:
- name: Creating a new directory
file:
path: "/etc/ansible/TESTE"
state: absent
---
- hosts: localhost
tasks:
- name: Creating a new directory
file:
path: "/etc/ansible/{{ item }}"
state: absent
with_items:
- test01.txt
- test02.txt
- test03.txt
- test04.txt
lucas@lucas-VirtualBox:/etc/ansible$ ls
ansible.cfg CONFIGS estudos_pdf file01.txt hosts JUNOS Linux-ansible projects PROJETO-ANSIBLE-JINJA2 show_run_192.168.1.99.cfg show_run_192.168.1.99.txt TEMPLATES