Day 5 – Ansible Notes – Pep – Aug – 2023
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
Storage - https://www.devopsschool.com/blog/storage-administrator-tasks-using-ansible/
OS - https://www.devopsschool.com/blog/system-administrator-tasks-in-os-servers-using-ansible/
DataBase - https://www.devopsschool.com/blog/ansible-modules-collections-for-database-maintenance-upgrade-and-patching/
https://oci-ansible-collection.readthedocs.io/en/latest/collections/oracle/oci/index.html
https://github.com/kosalaat/oracle_install/tree/master
------------------
Users
Shell --- cat /etc/passwd
script
bash
---
- name: List All Users on Linux
hosts: your_target_hosts
become: yes
tasks:
- name: Get list of all users
shell: "getent passwd | cut -d: -f1"
register: user_list
- name: Display user list
debug:
var: user_list.stdout_lines
main.yaml
import_playbook: users.yaml
import_playbook: app.yaml
import_playbook: lastlogin.yaml
Apps
Last Login
---
- name: List Installed Packages on CentOS/RHEL
hosts: your_target_hosts
become: yes
tasks:
- name: Get list of installed packages
shell: "rpm -qa"
register: package_list
- name: Display package list
debug:
var: package_list.stdout_lines
---
- name: List Installed Packages and Write Output to File
hosts: your_target_hosts
become: yes
tasks:
- name: Get list of installed packages
shell: "rpm -qa"
register: package_list
- name: Write package list to file
copy:
content: "{{ package_list.stdout }}"
dest: "/tmp/installed_packages.txt"
---
- name: Convert Comma-Separated Text to CSV
hosts: localhost
gather_facts: no
tasks:
- name: Read content from input file
slurp:
path: /path/to/input.txt
register: input_content
- name: Convert content to CSV format
set_fact:
csv_lines: "{{ input_content.content | b64decode | utf8 | replace(',', ';') | split('\n') }}"
- name: Write content to CSV file
copy:
content: "{{ csv_lines | join('\n') }}"
dest: /path/to/output.csv
---
- name: List Users Logged In Last 24 Hours
hosts: your_target_hosts
become: yes
tasks:
- name: Get list of users logged in last 24 hours
shell: "last | grep -E '{{ ansible_date_time.epoch|int - 86400 }}|still logged in' | awk '{print $1}' | sort -u"
register: recent_users
- name: Display recent user list
debug:
var: recent_users.stdout_lines
===========================================================================================
3 Options
--------------------------------------------------------
ansible-playbook > 11.txt
ansible-playbook -c playbook
------------------------
uptod
to be changed
ansible-playbook using jenkins
ansible-playbook using tower == awx
========================================
==============================================================
Ansible with Windows
================================================
ACS ARS
Linux Windows
---- winrm - http - 5985/86
---- DOT 4.5 - ps 3.0
Step 1 - Ansible in Windows - Setting Ansible Control Server
https://www.devopsschool.com/tutorial/ansible/ansible-windows-control-setup.html
Step 2 - https://www.devopsschool.com/tutorial/ansible/ansible-windows-remote-setup.html
Step 3 - https://www.devopsschool.com/tutorial/ansible/ansible-windows-adhoc-commands.html
Step 4 - https://www.devopsschool.com/tutorial/ansible/ansible-windows-playbooks.html
https://www.devopsschool.com/tutorial/ansible/ansible-windows-playbooks.html
https://www.devopsschool.com/tutorial/ansible/ansible-windows-adhoc-commands.html
Ansible Connection Options for windows remote Server
windows
https://docs.ansible.com/ansible/2.9/modules/list_of_windows_modules.html
[windows]
192.168.5.126
[windows:vars]
ansible_user=rajesh
ansible_password=rajesh123
ansible_connection=winrm
ansible_winrm_transport=basic
ansible_winrm_server_cert_validation=ignore
Notes - https://www.bestdevops.com/?s=Ansible+Notes
Slides
- https://devopsschool.com/slides/
- https://www.devopsschool.com/slide/
- https://www.scmgalaxy.com/slides/
Tutorials - https://www.devopsschool.com/blog/?s=ansible
Commands - https://www.devopsschool.com/commands
cheatsheets - https://www.devopsschool.com/cheatsheets/
Quiz - https://www.devopsschool.com/lms/course/view.php?id=42
https://www.devopsschool.com/blog/top-4-youtube-channel-for-free-videos-tutorials/
https://www.youtube.com/@DevSecOpsSchool
https://www.youtube.com/@sreschool
https://www.youtube.com/@debugschool
https://www.youtube.com/@Scmgalaxy
https://www.youtube.com/@TheDevOpsSchool
https://www.rajeshkumar.xyz/
=====================================================