https://github.com/praveenmethraskar/ansiblepractice
Ansible practice
https://github.com/praveenmethraskar/ansiblepractice
ansible ansible-playbook ansible-playbooks
Last synced: 17 days ago
JSON representation
Ansible practice
- Host: GitHub
- URL: https://github.com/praveenmethraskar/ansiblepractice
- Owner: praveenmethraskar
- Created: 2024-12-28T06:40:35.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-28T07:10:13.000Z (over 1 year ago)
- Last Synced: 2025-02-22T11:32:16.738Z (over 1 year ago)
- Topics: ansible, ansible-playbook, ansible-playbooks
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ansiblepractice
# Ansible installation commands
> sudo apt-add-repository ppa:ansible/ansible
> sudo apt update
> sudo apt install ansible
# Setting Up the Inventory File
> sudo nano /etc/ansible/hosts
> [servers]
> server1 ansible_host=public_ip
> server2 ansible_host=public_ip
> server3 ansible_host=public_ip
> [all:vars]
> ansible_python_interpreter=/usr/bin/python3
# commands for ansible
> ansible webservers -m user -a "name=web group=weblogic createhome=yes" -b : to create user and also attache to create group
> ansible webservers -m group -a "name=weblogic state=present" : to only create group by using ad-hoc command
> ansible webservers -a "df -h" to show disk space in worker node
> ansible -m apt -a "name=apache2 state=present" : to install packages into workernodes
> ansible -m module name> -a "name=apache2 state=present" : to install packages into workernodes
> ansible -m command -a " apt update -y" to run commands in workernodes
> [ansibel -m modulename -a "dest=/file name mode = 777 state = touch" ansibel -m file -a "dest=/file name mode = 777 state = touch" ]: to create file in workernodes
> ansibel -m file -a "dest=/ mode = 777 state =directory" : to create directory in workernodes
> ansible localhost -m file -a "dest=/opt/bmcdir mode=755 owner= group= state=directory"
> ansible -m (service) -a "name= (httpd) (apache2) state=started" to start the services in workernodes
# Run the job every 15 minutes
$ ansible -m cron -a "name='daily-cron-all-servers' minute=*/15
job='/path/to/minute-script.sh'"
# Run the job every four hours
$ ansible multi -s -m cron -a "name='daily-cron-all-servers' hour=4
job='/path/to/hour-script.sh'"
# Enabling a Job to run at system reboot
$ ansible multi -s -m cron -a "name='daily-cron-all-servers' special_time=reboot
job='/path/to/startup-script.sh'"
# Scheduling a Daily job
$ ansible -m cron -a "name='daily-cron-all-servers' special_time=daily
job='/path/to/daily-script.sh'"
# Scheduling a Weekly job
$ ansible -m cron -a "name='daily-cron-all-servers' special_time=weekly
job='/path/to/daily-script.sh'"
ansible -m copy -a "src=~/Downloads/index.html dest=/var/www/html owner=apache group=apache mode=0644" : to copy file from master to slave opt/bmcdiry
# playbook.yaml execution command
>ansible-playbook -i /etc/ansible/hosts playbook.yaml