summaryrefslogtreecommitdiff
path: root/ansible-practice
diff options
context:
space:
mode:
Diffstat (limited to 'ansible-practice')
-rw-r--r--ansible-practice/02-playbook-list-files.yml2
-rw-r--r--ansible-practice/04-playbook-create-file.yml2
-rw-r--r--ansible-practice/05-playbook-add-content-to-created-file.yml2
-rw-r--r--ansible-practice/system/12-replace-text.yml42
-rw-r--r--ansible-practice/system/12-replace-text.yml~15
-rw-r--r--ansible-practice/system/13-create-update-user.yml42
-rw-r--r--ansible-practice/system/13-create-update-user.yml~8
-rw-r--r--ansible-practice/system/14-verify-user.yml28
-rw-r--r--ansible-practice/system/14-verify-user.yml~19
9 files changed, 157 insertions, 3 deletions
diff --git a/ansible-practice/02-playbook-list-files.yml b/ansible-practice/02-playbook-list-files.yml
index 1163a2d..9240059 100644
--- a/ansible-practice/02-playbook-list-files.yml
+++ b/ansible-practice/02-playbook-list-files.yml
@@ -8,7 +8,7 @@
# connection: local
tasks:
- name: "just execute a ls -lrt command"
- shell: "ls -lrt"
+ ansible.builtin.shell: "ls -lrt"
register: "output"
- debug: var=output.stdout_lines
diff --git a/ansible-practice/04-playbook-create-file.yml b/ansible-practice/04-playbook-create-file.yml
index d9676e9..19afb03 100644
--- a/ansible-practice/04-playbook-create-file.yml
+++ b/ansible-practice/04-playbook-create-file.yml
@@ -9,7 +9,7 @@
# connection: local
tasks:
- name: Creating an empty file
- file:
+ ansible.builtin.file:
path: "~/ansible_created_file-01.txt"
state: touch
... \ No newline at end of file
diff --git a/ansible-practice/05-playbook-add-content-to-created-file.yml b/ansible-practice/05-playbook-add-content-to-created-file.yml
index 60b1c05..decf848 100644
--- a/ansible-practice/05-playbook-add-content-to-created-file.yml
+++ b/ansible-practice/05-playbook-add-content-to-created-file.yml
@@ -8,7 +8,7 @@
connection: local
tasks:
- name: Creating a file with content
- copy:
+ ansible.builtin.copy:
dest: "~/tmp/temp_files/ansible_created_file-02.txt"
content: |
line 01
diff --git a/ansible-practice/system/12-replace-text.yml b/ansible-practice/system/12-replace-text.yml
new file mode 100644
index 0000000..4ae07a6
--- /dev/null
+++ b/ansible-practice/system/12-replace-text.yml
@@ -0,0 +1,42 @@
+#
+# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/replace_module.html
+#
+---
+- name: "12 - custom ansible - replace text"
+ hosts: dev
+ tasks:
+ - name: update slackpg blacklist - blacklist kernels
+ ansible.builtin.replace:
+ path: "{{ backup_etc_dir }}/blacklist"
+ regexp: '#kernel'
+ replace: 'kernel'
+ tags: ['slackpkg_blacklist_kernels']
+
+ - name: update slackpg blacklist - blacklist SBo packages
+ ansible.builtin.replace:
+ path: "{{ backup_etc_dir }}/blacklist"
+ regexp: '#\[0-9\]'
+ replace: '[0-9]'
+ tags: ['slackpkg_blacklist_sbo']
+
+ # this will add a line to a file if it does not exist !!
+ - name: update slackpg blacklist - blacklist alienbob packages
+ ansible.builtin.lineinfile:
+ path: "{{ backup_etc_dir }}/blacklist"
+ search_string: '\[0-9\]\+alien'
+ line: '[0-9]+alien'
+ tags: ['slackpkg_blacklist_alien']
+
+ - name: update slackpg blacklist - blacklist sbopkg packages
+ ansible.builtin.lineinfile:
+ path: "{{ backup_etc_dir }}/blacklist"
+ search_string: 'sbopkg'
+ line: 'sbopkg'
+ tags: ['slackpkg_blacklist_sbopkg']
+
+ - name: update slackpg blacklist - blacklist kde packages
+ ansible.builtin.lineinfile:
+ path: "{{ backup_etc_dir }}/blacklist"
+ search_string: 'kde\/'
+ line: 'kde/'
+ tags: ['slackpkg_blacklist_kde']
diff --git a/ansible-practice/system/12-replace-text.yml~ b/ansible-practice/system/12-replace-text.yml~
new file mode 100644
index 0000000..1848ea6
--- /dev/null
+++ b/ansible-practice/system/12-replace-text.yml~
@@ -0,0 +1,15 @@
+---
+- name: "12 - custom ansible - replace text"
+ hosts: dev
+ tasks:
+ - name: update slackpg blacklist
+ ansible.builtin.replace:
+ path: "{{ backup_etc_dir }}/blacklist"
+ # regexp: '^#(kernel-.+)$'
+ # replace: '\1'
+ regexp: "kernel"
+ replace: "kerneldaryll"
+ owner: root
+ group: root
+ backup: yes
+ tags: ['slackpkg_blacklist']
diff --git a/ansible-practice/system/13-create-update-user.yml b/ansible-practice/system/13-create-update-user.yml
new file mode 100644
index 0000000..b00af34
--- /dev/null
+++ b/ansible-practice/system/13-create-update-user.yml
@@ -0,0 +1,42 @@
+#
+# https://www.howtouselinux.com/post/create-user-with-ansible
+# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html
+# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html
+# https://docs.ansible.com/ansible/latest/collections/community/crypto/openssh_keypair_module.html
+# https://www.codesandnotes.be/2020/01/13/generate-ssh-keys-using-ansible/
+#
+---
+- name: "13 - custom ansible - create/update user"
+ hosts: dev
+ become: yes # Run tasks with root/sudo privileges
+ vars:
+ username: testuser1
+ password: mypassword
+ passphrase: one two three
+
+ tasks:
+ - name: create user
+ ansible.builtin.user:
+ name: "{{ username }}"
+ password: "{{ password | password_hash('sha512') }}" # encrypted password
+ state: present # ensure the user is present
+ createhome: true # create the users home directory
+ shell: /bin/bash
+ group: users # slackware default
+ groups: audio,cdrom,floppy,input,lp,netdev,plugdev,power,scanner,video,wheel
+ generate_ssh_key: true
+ ssh_key_type: ed25519
+ ssh_key_passphrase: "{{ passphrase }}"
+
+#
+# received the following when running this playbook:
+#
+# TASK [create user] *************************************************
+#
+# [DEPRECATION WARNING]: Encryption using the Python crypt module is
+# deprecated. The Python crypt module is deprecated and will be removed
+# from Python 3.13. Install the passlib library for continued encryption
+# functionality. This feature will be removed in version
+# 2.17. Deprecation warnings can be disabled by setting
+# deprecation_warnings=False in ansible.cfg.
+#
diff --git a/ansible-practice/system/13-create-update-user.yml~ b/ansible-practice/system/13-create-update-user.yml~
new file mode 100644
index 0000000..d7fc422
--- /dev/null
+++ b/ansible-practice/system/13-create-update-user.yml~
@@ -0,0 +1,8 @@
+#
+# https://www.howtouselinux.com/post/create-user-with-ansible
+#
+---
+- name: "13 - custom ansible - create/update user"
+ hosts: dev
+ become: yes # Run tasks with root/sudo privileges
+ tasks:
diff --git a/ansible-practice/system/14-verify-user.yml b/ansible-practice/system/14-verify-user.yml
new file mode 100644
index 0000000..8b785b1
--- /dev/null
+++ b/ansible-practice/system/14-verify-user.yml
@@ -0,0 +1,28 @@
+#
+# https://www.howtouselinux.com/post/create-user-with-ansible
+# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html
+# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html
+#
+---
+- name: "14 - custom ansible - verifyl user"
+ hosts: dev
+ become: yes # Run tasks with root/sudo privileges
+ vars:
+ username: testuser1
+
+ tasks:
+ - name: check if user exists
+ ansible.builtin.command: id {{ username }}
+# ansible.builtin.shell: id {{ username }}
+ register: user_check
+ ignore_errors: true
+
+ - name: display user information
+ ansible.builtin.debug:
+ msg: user '{{ username }}' exists !
+ when: user_check.rc == 0
+
+ - name: display error message if user does not exist
+ ansible.builtin.debug:
+ msg: user '{{ username }}' does not exist !
+ when: user_check.rc != 0
diff --git a/ansible-practice/system/14-verify-user.yml~ b/ansible-practice/system/14-verify-user.yml~
new file mode 100644
index 0000000..4be4c36
--- /dev/null
+++ b/ansible-practice/system/14-verify-user.yml~
@@ -0,0 +1,19 @@
+#
+# https://www.howtouselinux.com/post/create-user-with-ansible
+#
+---
+- name: "14 - custom ansible - verifyl user"
+ hosts: dev
+ become: yes # Run tasks with root/sudo privileges
+
+ tasks:
+ - name: check if user exists
+ ansible.builtin.shell:
+ register: user_check
+ ignore_errors: true
+
+ - name: display user information
+ ansible.builtin.debug:
+ msg: "user '{{ username }}' exists !"
+ when: user_check.rc == 0
+