File tree Expand file tree Collapse file tree 9 files changed +126
-0
lines changed
secure-backups/ansible1/var/log Expand file tree Collapse file tree 9 files changed +126
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ - name : File operations
3+ hosts : ansible1
4+ tasks :
5+ # - name: Create a blank file
6+ # file:
7+ # path: ~/501_file.txt
8+ # owner: ansible
9+ # group: ansible
10+ # mode: 0600
11+ # state: touch
12+ - name : Create a blank file
13+ file :
14+ path : /home/ansible/501_file.txt
15+ owner : ansible
16+ group : ansible
17+ mode : 0600
18+ state : touch
19+ setype : httpd_sys_content_t
20+
21+ - name : Add line to a file
22+ lineinfile :
23+ path : /home/ansible/501_file.txt
24+ line : " Add this line to the file"
25+ state : present
26+
27+ - name : Add block to a file
28+ blockinfile :
29+ path : /home/ansible/501_file.txt
30+ block : |
31+ First line in the block
32+ Second line in the block
33+ state : present
34+
35+ - name : Get a md5 hash sum
36+ stat :
37+ path : /home/ansible/501_file.txt
38+ checksum_algorithm : md5
39+ register : result
40+ - name : Print a stat result
41+ debug :
42+ msg : [
43+ " {{ result.stat }}" ,
44+ " ##########################" ,
45+ " {{ result.stat.checksum }}"
46+ ]
Original file line number Diff line number Diff line change 1+ ---
2+ - name : File operations
3+ hosts : ansible1
4+ tasks :
5+ - name : Remove file
6+ file :
7+ path : /home/ansible/501_file.txt
8+ state : absent
9+
Original file line number Diff line number Diff line change 1+ ---
2+ - name : Test rsync
3+ hosts : ansible1
4+ vars :
5+ src_file_path : files/text.file
6+ dest_file_path : /home/ansible/text.file
7+ tasks :
8+ - name : Debug
9+ debug :
10+ msg : [
11+ " {{ src_file_path }}" ,
12+ " {{ dest_file_path }}"
13+ ]
14+ - name : Syncronize a text file
15+ synchronize :
16+ src : " {{ src_file_path }}"
17+ dest : " {{ dest_file_path }}"
Original file line number Diff line number Diff line change 1+ ---
2+ - name : Fetch security logs from managed host
3+ hosts : ansible1
4+ tasks :
5+ - name : Fetch /var/log/secure
6+ fetch :
7+ src : /var/log/secure
8+ dest : secure-backups/
Original file line number Diff line number Diff line change 1+ ---
2+ - name : Create a file in devops homedir
3+ hosts : ansible1
4+ tasks :
5+ - name : Copy file to dest host
6+ copy :
7+ src : files/users.txt
8+ dest : /home/devops/users.txt
9+ owner : devops
10+ group : devops
11+ mode : u+rw,g-rx,o-rx
12+ # mode: 0600
13+ # setype: samba_share_t
14+
15+ # - name: Update SE setting for a file
16+ # file:
17+ # path: /home/devops/users.txt
18+ # selevel: _default
19+ # serole: _default
20+ # setype: _default
21+ # seuser: _default
22+
23+
Original file line number Diff line number Diff line change 1+ ---
2+ - name : Update a file in devops homedir
3+ hosts : ansible1
4+ tasks :
5+ - name : Add line to the users.txt
6+ lineinfile :
7+ path : /home/devops/users.txt
8+ line : " This line was added by ansible script"
9+ state : present
10+
11+ - name : Add users records to the users.txt
12+ lineinfile :
13+ path : /home/devops/users.txt
14+ line : " {{ item }}"
15+ state : present
16+ loop :
17+ - root
18+ - ansible
19+ - devops
Original file line number Diff line number Diff line change 1+ This is a text file to rsync
2+
3+ We are starting chapter 5 now
Original file line number Diff line number Diff line change 1+ This was a blank file for tests
You can’t perform that action at this time.
0 commit comments