diff --git a/inventory b/inventory new file mode 100644 index 0000000..b5eff83 --- /dev/null +++ b/inventory @@ -0,0 +1,2 @@ +[webservers] +192.168.147.187 ansible_user=root diff --git a/playbooks/01_app_install.yml b/playbooks/01_app_install.yml new file mode 100644 index 0000000..09ba514 --- /dev/null +++ b/playbooks/01_app_install.yml @@ -0,0 +1,19 @@ +--- +- name: Install and Start the service + hosts: all + vars: + - app: httpd + + tasks: + - name: Installing nginx + yum: + name: "{{ app }}" + state: present + tags: i-nginx + + - name: Starting the nginx service + service: + name: "{{ app }}" + state: started + enabled: true + tags: ss-nginx diff --git a/playbooks/02_copy_files.yml b/playbooks/02_copy_files.yml new file mode 100644 index 0000000..527c06a --- /dev/null +++ b/playbooks/02_copy_files.yml @@ -0,0 +1,13 @@ +--- +- name: Copying files to remote + hosts: all + + tasks: + - name: Copy files + copy: + src: /root/myfile.txt + dest: /tmp/ + owner: paul + group: paul + mode: ugo=rw + backup: true diff --git a/playbooks/03_files_mod.yml b/playbooks/03_files_mod.yml new file mode 100644 index 0000000..450f3c9 --- /dev/null +++ b/playbooks/03_files_mod.yml @@ -0,0 +1,17 @@ +--- +- name: File Module + hosts: all + + tasks: + - name: Creating a file + file: + path: /tmp/newfile.txt + state: absent + owner: paul + group: paul + mode: u=rwx,g=rw,o=r + + - name: Creating a directory + file: + path: /tmp/myfolder + state: absent diff --git a/playbooks/04_change_permission.yml b/playbooks/04_change_permission.yml new file mode 100644 index 0000000..e016aca --- /dev/null +++ b/playbooks/04_change_permission.yml @@ -0,0 +1,9 @@ +--- +- name: change permissions + hosts: all + + tasks: + - name: change perm + file: + path: /tmp/myfile.txt + mode: u=r,g=rw diff --git a/playbooks/05_script_run.yml b/playbooks/05_script_run.yml new file mode 100644 index 0000000..cf29266 --- /dev/null +++ b/playbooks/05_script_run.yml @@ -0,0 +1,10 @@ +--- +- name: Run a script + hosts: all + + tasks: + - name: Run script + shell: ./test.sh >> test.log + args: + chdir: /tmp/script/ + creates: test.log diff --git a/playbooks/06_cron_jobs.yml b/playbooks/06_cron_jobs.yml new file mode 100644 index 0000000..1c4b354 --- /dev/null +++ b/playbooks/06_cron_jobs.yml @@ -0,0 +1,16 @@ +--- +- name: Cron Setup + hosts: all + + tasks: + - name: Add Cron Job + cron: + name: Run Test Script + minute: 30 + hour: 20 + day: 15 + month: "*" + weekday: "*" + user: paul + job: /tmp/script/test.sh + disabled: yes diff --git a/playbooks/07_cron_modify.yml b/playbooks/07_cron_modify.yml new file mode 100644 index 0000000..7225c6c --- /dev/null +++ b/playbooks/07_cron_modify.yml @@ -0,0 +1,13 @@ +--- +- name: Modify Cron + hosts: all + + tasks: + - name: Remove Cron Job + cron: + name: VARR + env: yes + user: paul + job: /tmp/script/test.sh + insertafter: PATH + state: absent diff --git a/playbooks/08_user_mgm.yml b/playbooks/08_user_mgm.yml new file mode 100644 index 0000000..2d086b7 --- /dev/null +++ b/playbooks/08_user_mgm.yml @@ -0,0 +1,14 @@ +--- +- name: User Mgm + hosts: all + + tasks: + - name: User Creation + user: + name: "{{ item }}" + comment: new user adding for QA Team + shell: /bin/bash + loop: + - Raju + - Sham + - Baburao diff --git a/playbooks/09_set_passwd.yml b/playbooks/09_set_passwd.yml new file mode 100644 index 0000000..abbe0a3 --- /dev/null +++ b/playbooks/09_set_passwd.yml @@ -0,0 +1,10 @@ +--- +- name: Set Password + hosts: all + + tasks: + - name: Set passwd + user: + name: nick + update_password: always + password: "{{'abcd12345' | password_hash('sha512', 'mysecretcode')}}" diff --git a/playbooks/10_download_file.yml b/playbooks/10_download_file.yml new file mode 100644 index 0000000..e7f3e38 --- /dev/null +++ b/playbooks/10_download_file.yml @@ -0,0 +1,12 @@ +--- +- name: Downlaod files + hosts: all + + tasks: + - name: Download file + get_url: + url: https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tar.xz + dest: /tmp/script/ + owner: paul + group: paul + mode: 0777 diff --git a/playbooks/11_kill_process.yml b/playbooks/11_kill_process.yml new file mode 100644 index 0000000..21f4b3d --- /dev/null +++ b/playbooks/11_kill_process.yml @@ -0,0 +1,13 @@ +--- +- name: Kill a process + hosts: all + + tasks: + - name: Find a process and kill it + ignore_errors: yes + shell: "pgrep nginx | xargs kill" + + - name: Start the service + service: + name: nginx + state: started diff --git a/playbooks/12_firewalld.yml b/playbooks/12_firewalld.yml new file mode 100644 index 0000000..c472417 --- /dev/null +++ b/playbooks/12_firewalld.yml @@ -0,0 +1,21 @@ +--- +- name: Firewall changes + hosts: all + become: true + + tasks: + - name: Enable a service in firewalldd + firewalld: + port: 80/tcp + permanent: true + state: disabled + notify: + - Reload firewalld + + handlers: + - name: Reload firewalld + service: + name: firewalld + state: reloaded + + diff --git a/playbooks/13_conditions.yml b/playbooks/13_conditions.yml new file mode 100644 index 0000000..8f18021 --- /dev/null +++ b/playbooks/13_conditions.yml @@ -0,0 +1,16 @@ +--- +- name: Installing Httpd + hosts: all + + tasks: + - name: Install httpd on Redhat + yum: + name: httpd + state: present + when: ansible_os_family == "RedHat" + + - name: Install apache2 on Ubuntu + apt: + name: apache2 + state: present + when: ansible_os_family == "Ubuntu" diff --git a/playbooks/14_for_loop.yml b/playbooks/14_for_loop.yml new file mode 100644 index 0000000..9899a9a --- /dev/null +++ b/playbooks/14_for_loop.yml @@ -0,0 +1,16 @@ +--- +- name: Install and Start the service + hosts: all + vars: + - apps: [yum,httpd,vim,telnet] + + tasks: + - name: Installing nginx + yum: + name: "{{ item }}" + state: present + tags: i-nginx + with_items: "{{ apps }}" + + + diff --git a/playbooks/first_pb.yml b/playbooks/first_pb.yml new file mode 100644 index 0000000..81c983b --- /dev/null +++ b/playbooks/first_pb.yml @@ -0,0 +1,9 @@ +--- +- name: First Basic PB + hosts: all + + tasks: + - name: Test Connectivity + ping: + - name: "Print Output" + debug: msg="Alright!!" diff --git a/playbooks/roles_demo.yml b/playbooks/roles_demo.yml new file mode 100644 index 0000000..63a7fd9 --- /dev/null +++ b/playbooks/roles_demo.yml @@ -0,0 +1,6 @@ +--- +- name: Install httpd and Firewall changes + hosts: all + roles: + - httpd_setup + - fwd_service diff --git a/playbooks/webserver_update.yml b/playbooks/webserver_update.yml new file mode 100644 index 0000000..0da46c0 --- /dev/null +++ b/playbooks/webserver_update.yml @@ -0,0 +1,18 @@ +- name: Upload new code and ReStart the service + hosts: localhost:90 + vars: + app: httpd + + tasks: + - name: Place custom HTML File + copy: + src: /var/lib/jenkins/workspace/website-update/index.html + dest: /var/www/html/index.html + become: true + + - name: Start the service + service: + name: httpd + state: restarted + enabled: yes + become: true diff --git a/test.py b/test.py index b82199f..c0605a2 100644 --- a/test.py +++ b/test.py @@ -1 +1 @@ -print("Wassup Buddy!! v9") +print("Wassup Abhi v2!!")