[root@controller ~]# cat createMfilesNdir.yml
- hosts: localhost
become: true
tasks:
- name: Create multiple files
file: path={{item}} state=touch
with_items:
- '/home/kiran/file1.txt'
- '/home/kiran/file2.txt'
- '/home/kiran/file3.txt'
- name: Create multiple directories
file: path={{item}} state=directory
with_items:
- '/home/kiran/dir1'
- '/home/kiran/dir2'
- '/home/kiran/dir3'
[root@controller ~]#
[root@controller ~]# ansible-playbook createMfilesNdir.yml
PLAY [localhost] *******************************************************************
TASK [Gathering Facts] *************************************************************
ok: [localhost]
TASK [Create multiple files] *******************************************************
changed: [localhost] => (item=/home/kiran/file1.txt)
changed: [localhost] => (item=/home/kiran/file2.txt)
changed: [localhost] => (item=/home/kiran/file3.txt)
TASK [Create multiple directories] *************************************************
changed: [localhost] => (item=/home/kiran/dir1)
changed: [localhost] => (item=/home/kiran/dir2)
changed: [localhost] => (item=/home/kiran/dir3)
PLAY RECAP *************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0
[root@controller ~]#
[root@controller ~]# cd /home/kiran
[root@controller kiran]# ls -ltr
total 0
-rw-r--r-- 1 root root 0 Oct 18 14:42 kiran.txt
drwxrwxr-x 2 kiran kiran 6 Oct 18 14:47 kiran
-rw-r--r-- 1 root root 0 Oct 18 14:59 file1.txt
-rw-r--r-- 1 root root 0 Oct 18 14:59 file2.txt
-rw-r--r-- 1 root root 0 Oct 18 14:59 file3.txt
drwxr-xr-x 2 root root 6 Oct 18 14:59 dir1
drwxr-xr-x 2 root root 6 Oct 18 14:59 dir2
drwxr-xr-x 2 root root 6 Oct 18 14:59 dir3
[root@controller kiran]#
- hosts: localhost
become: true
tasks:
- name: Create multiple files
file: path={{item}} state=touch
with_items:
- '/home/kiran/file1.txt'
- '/home/kiran/file2.txt'
- '/home/kiran/file3.txt'
- name: Create multiple directories
file: path={{item}} state=directory
with_items:
- '/home/kiran/dir1'
- '/home/kiran/dir2'
- '/home/kiran/dir3'
[root@controller ~]#
[root@controller ~]# ansible-playbook createMfilesNdir.yml
PLAY [localhost] *******************************************************************
TASK [Gathering Facts] *************************************************************
ok: [localhost]
TASK [Create multiple files] *******************************************************
changed: [localhost] => (item=/home/kiran/file1.txt)
changed: [localhost] => (item=/home/kiran/file2.txt)
changed: [localhost] => (item=/home/kiran/file3.txt)
TASK [Create multiple directories] *************************************************
changed: [localhost] => (item=/home/kiran/dir1)
changed: [localhost] => (item=/home/kiran/dir2)
changed: [localhost] => (item=/home/kiran/dir3)
PLAY RECAP *************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0
[root@controller ~]#
[root@controller ~]# cd /home/kiran
[root@controller kiran]# ls -ltr
total 0
-rw-r--r-- 1 root root 0 Oct 18 14:42 kiran.txt
drwxrwxr-x 2 kiran kiran 6 Oct 18 14:47 kiran
-rw-r--r-- 1 root root 0 Oct 18 14:59 file1.txt
-rw-r--r-- 1 root root 0 Oct 18 14:59 file2.txt
-rw-r--r-- 1 root root 0 Oct 18 14:59 file3.txt
drwxr-xr-x 2 root root 6 Oct 18 14:59 dir1
drwxr-xr-x 2 root root 6 Oct 18 14:59 dir2
drwxr-xr-x 2 root root 6 Oct 18 14:59 dir3
[root@controller kiran]#
Comments
Post a Comment