Skip to content

Commit 3181651

Browse files
Chap 5 started
1 parent 928f521 commit 3181651

File tree

9 files changed

+126
-0
lines changed

9 files changed

+126
-0
lines changed

501_create_a_file.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
]

502_remove_a_file.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+

503_test_rsync.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 }}"

504_get_security_logs.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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/

505_create_file_for_devops.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+

506_update_file_for_devops.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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

files/text.file

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is a text file to rsync
2+
3+
We are starting chapter 5 now

files/users.txt

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This was a blank file for tests

0 commit comments

Comments
 (0)