├── README.md ├── ansible-vault.yml ├── ansible.cfg ├── ansible_udemy_course.PNG ├── copy_file.yml ├── create_file.yml ├── create_user.yml ├── hosts ├── index.html ├── install_apache2.yml ├── install_apache_httpd.yml ├── install_httpd.yml ├── install_packages.yml ├── pass.yml ├── setup-apache.yml ├── setup-apache ├── .travis.yml ├── README.md ├── defaults │ └── main.yml ├── files │ └── index.html ├── handlers │ └── main.yml ├── tasks │ └── main.yml └── vars │ └── main.yml ├── setup-apache_backup.yml ├── setup-tomcat.yml ├── uninstall_httpd.yml ├── user.yml └── vault-pass.yml /README.md: -------------------------------------------------------------------------------- 1 | # ansible_for_beginners 2 | 3 | ## find full course over here 4 | 5 | [![Image](https://github.com/yankils/ansible_for_beginners/blob/master/ansible_udemy_course.PNG "Ansible for the DevOps Beginners & System Admins ")](https://www.udemy.com/course/valaxy-ansible/?referralCode=9F36DC2010AEB6D64263) 6 | -------------------------------------------------------------------------------- /ansible-vault.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: ansible palybook to test ansible vault 3 | hosts: all 4 | become: true 5 | vars_files: 6 | - vault-pass.yml 7 | tasks: 8 | - name: clone a repo 9 | git: 10 | repo: https://yankils:{{ password }}@github.com/yankils/vault.git 11 | dest: /opt/ansadmin/test-vault 12 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | inventory = /opt/ansible/hosts 3 | 4 | -------------------------------------------------------------------------------- /ansible_udemy_course.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yankils/ansible_for_beginners/662247cf70148ed2eb51fafa51bb01ff5bef0e1b/ansible_udemy_course.PNG -------------------------------------------------------------------------------- /copy_file.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: ansible playbook to copy a file 3 | hosts: all 4 | become: true 5 | tasks: 6 | - name: copy a file 7 | copy: 8 | src: /opt/ansible/index.html 9 | dest: /home/ansadmin 10 | mode: 0600 11 | owner: john 12 | -------------------------------------------------------------------------------- /create_file.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: this playbook creates a file or dir 3 | hosts: all 4 | # become: true 5 | # gather_facts: no 6 | tasks: 7 | - name: creating a file 8 | file: 9 | path: /home/ansadmin/dir1 10 | state: directory 11 | -------------------------------------------------------------------------------- /create_user.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: this playbook is to create user 3 | hosts: all 4 | become: true 5 | vars_files: 6 | - user.yml 7 | tasks: 8 | - name: creating user {{ user }} 9 | user: 10 | name: "{{ user }}" 11 | -------------------------------------------------------------------------------- /hosts: -------------------------------------------------------------------------------- 1 | [webservers] 2 | 172.31.30.140 3 | 172.31.16.135 4 | 5 | [appservers] 6 | 172.31.16.135 7 | 8 | [dbservers] 9 | 172.31.27.43 10 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 |

Welcome to Apache tomcat

2 | -------------------------------------------------------------------------------- /install_apache2.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install apache2 on ubuntu server 3 | hosts: dbservers 4 | become: true 5 | tasks: 6 | - name: install apache2 7 | apt: 8 | name: apache2 9 | state: present 10 | 11 | - name: start apache2 12 | service: 13 | name: apache2 14 | state: started 15 | -------------------------------------------------------------------------------- /install_apache_httpd.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: this playbook install httpd 3 | hosts: all 4 | become: true 5 | tasks: 6 | - name: install package 7 | yum: 8 | name: httpd 9 | state: installed 10 | when: ansible_os_family == "RedHat" 11 | 12 | - name: start apache 13 | service: 14 | name: httpd 15 | state: started 16 | when: ansible_os_family == "RedHat" 17 | 18 | - name: install apache2 19 | apt: 20 | name: apache2 21 | state: present 22 | when: ansible_os_family == "Debian" 23 | 24 | - name: start apache2 25 | service: 26 | name: apache2 27 | state: started 28 | when: ansible_os_family == "Debian" 29 | 30 | - name: copy index.html 31 | copy: 32 | src: /opt/ansible/index.html 33 | dest: /var/www/html 34 | mode: 0666 35 | -------------------------------------------------------------------------------- /install_httpd.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: this playbook install httpd 3 | hosts: webservers 4 | become: true 5 | tasks: 6 | - name: install package 7 | yum: 8 | name: httpd 9 | state: installed 10 | notify: start apache 11 | 12 | handlers: 13 | - name: start apache 14 | service: 15 | name: httpd 16 | state: started 17 | 18 | -------------------------------------------------------------------------------- /install_packages.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: this playbook install pacakges 3 | hosts: webservers 4 | become: true 5 | tasks: 6 | - name: install package 7 | yum: 8 | # name: ['git', 'make', 'gcc', 'wget', 'telnet', 'gzip'] 9 | name: "{{ item }}" 10 | state: installed 11 | with_items: 12 | - git 13 | - make 14 | - gcc 15 | - wget 16 | - telnet 17 | - gzip 18 | -------------------------------------------------------------------------------- /pass.yml: -------------------------------------------------------------------------------- 1 | abc123 2 | -------------------------------------------------------------------------------- /setup-apache.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: this playbook install httpd 3 | hosts: all 4 | become: true 5 | roles: 6 | - setup-apache 7 | -------------------------------------------------------------------------------- /setup-apache/.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | 5 | # Use the new container infrastructure 6 | sudo: false 7 | 8 | # Install ansible 9 | addons: 10 | apt: 11 | packages: 12 | - python-pip 13 | 14 | install: 15 | # Install ansible 16 | - pip install ansible 17 | 18 | # Check ansible version 19 | - ansible --version 20 | 21 | # Create ansible.cfg with correct roles_path 22 | - printf '[defaults]\nroles_path=../' >ansible.cfg 23 | 24 | script: 25 | # Basic role syntax check 26 | - ansible-playbook tests/test.yml -i tests/inventory --syntax-check 27 | 28 | notifications: 29 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ -------------------------------------------------------------------------------- /setup-apache/README.md: -------------------------------------------------------------------------------- 1 | Role Name 2 | ========= 3 | 4 | A brief description of the role goes here. 5 | 6 | Requirements 7 | ------------ 8 | 9 | Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. 10 | 11 | Role Variables 12 | -------------- 13 | 14 | A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. 15 | 16 | Dependencies 17 | ------------ 18 | 19 | A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. 20 | 21 | Example Playbook 22 | ---------------- 23 | 24 | Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: 25 | 26 | - hosts: servers 27 | roles: 28 | - { role: username.rolename, x: 42 } 29 | 30 | License 31 | ------- 32 | 33 | BSD 34 | 35 | Author Information 36 | ------------------ 37 | 38 | An optional section for the role authors to include contact information, or a website (HTML is not allowed). 39 | -------------------------------------------------------------------------------- /setup-apache/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for setup-apache 3 | port: 8080 4 | -------------------------------------------------------------------------------- /setup-apache/files/index.html: -------------------------------------------------------------------------------- 1 |

Welcome to Apache tomcat

2 | -------------------------------------------------------------------------------- /setup-apache/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for setup-apache 3 | - name: start apache 4 | service: 5 | name: httpd 6 | state: started 7 | 8 | - name: start apache2 9 | service: 10 | name: apache2 11 | state: started 12 | 13 | - name: restart apache 14 | service: 15 | name: httpd 16 | state: restarted 17 | 18 | - name: restart apache2 19 | service: 20 | name: apache2 21 | state: restarted 22 | -------------------------------------------------------------------------------- /setup-apache/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for setup-apache 3 | - name: install package 4 | yum: 5 | name: httpd 6 | state: installed 7 | when: ansible_os_family == "RedHat" 8 | notify: start apache 9 | 10 | - name: install apache2 11 | apt: 12 | name: apache2 13 | state: present 14 | when: ansible_os_family == "Debian" 15 | notify: start apache2 16 | 17 | - name: copy index.html 18 | copy: 19 | src: /opt/ansible/index.html 20 | dest: /var/www/html 21 | mode: 0666 22 | 23 | - name: Ensure the default Apache port is {{ port }} 24 | lineinfile: 25 | path: /etc/httpd/conf/httpd.conf 26 | regexp: '^Listen ' 27 | insertafter: '^#Listen ' 28 | line: Listen {{ port }} 29 | when: ansible_os_family == "RedHat" 30 | notify: restart apache 31 | 32 | - name: Ensure the default Apache port is {{ port }} on ubuntu 33 | lineinfile: 34 | path: /etc/apache2/ports.conf 35 | regexp: '^Listen ' 36 | insertafter: "# /etc/apache2/sites-enabled/000-default.conf" 37 | line: Listen {{ port }} 38 | when: ansible_os_family == "Debian" 39 | notify: restart apache2 40 | -------------------------------------------------------------------------------- /setup-apache/vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for setup-apache 3 | #port: 8082 4 | -------------------------------------------------------------------------------- /setup-apache_backup.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: this playbook install httpd 3 | hosts: all 4 | become: true 5 | vars: 6 | port: 8082 7 | tasks: 8 | - name: install package 9 | yum: 10 | name: httpd 11 | state: installed 12 | when: ansible_os_family == "RedHat" 13 | notify: start apache 14 | 15 | - name: install apache2 16 | apt: 17 | name: apache2 18 | state: present 19 | when: ansible_os_family == "Debian" 20 | notify: start apache2 21 | 22 | - name: copy index.html 23 | copy: 24 | src: /opt/ansible/index.html 25 | dest: /var/www/html 26 | mode: 0666 27 | 28 | - name: Ensure the default Apache port is {{ port }} 29 | lineinfile: 30 | path: /etc/httpd/conf/httpd.conf 31 | regexp: '^Listen ' 32 | insertafter: '^#Listen ' 33 | line: Listen {{ port }} 34 | when: ansible_os_family == "RedHat" 35 | notify: restart apache 36 | 37 | - name: Ensure the default Apache port is {{ port }} on ubuntu 38 | lineinfile: 39 | path: /etc/apache2/ports.conf 40 | regexp: '^Listen ' 41 | insertafter: "# /etc/apache2/sites-enabled/000-default.conf" 42 | line: Listen {{ port }} 43 | when: ansible_os_family == "Debian" 44 | notify: restart apache2 45 | 46 | handlers: 47 | - name: start apache 48 | service: 49 | name: httpd 50 | state: started 51 | 52 | - name: start apache2 53 | service: 54 | name: apache2 55 | state: started 56 | 57 | - name: restart apache 58 | service: 59 | name: httpd 60 | state: restarted 61 | 62 | - name: restart apache2 63 | service: 64 | name: apache2 65 | state: restarted 66 | -------------------------------------------------------------------------------- /setup-tomcat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: setup tomcat 3 | hosts: all 4 | become: true 5 | tasks: 6 | - name: install java 7 | yum: 8 | name: java 9 | state: installed 10 | when: ansible_os_family == "RedHat" 11 | 12 | - name: install java on ubuntu 13 | apt: 14 | name: default-jdk 15 | state: present 16 | when: ansible_os_family == "Debian" 17 | 18 | - name: download tomcat packages 19 | get_url: 20 | url: http://mirrors.estointernet.in/apache/tomcat/tomcat-8/v8.5.50/bin/apache-tomcat-8.5.50.tar.gz 21 | dest: /opt 22 | 23 | - name: untar apache packages 24 | unarchive: 25 | src: /opt/apache-tomcat-8.5.50.tar.gz 26 | dest: /opt 27 | remote_src: yes 28 | 29 | - name: add execution permissions on startup.sh file 30 | file: 31 | path: /opt/apache-tomcat-8.5.50/bin/startup.sh 32 | mode: 0777 33 | 34 | - name: start tomcat services 35 | shell: nohup ./startup.sh 36 | args: 37 | chdir: /opt/apache-tomcat-8.5.50/bin 38 | -------------------------------------------------------------------------------- /uninstall_httpd.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: this playbook uninstall httpd 3 | hosts: all 4 | become: true 5 | tasks: 6 | - name: stop httpd service 7 | service: 8 | name: httpd 9 | state: stopped 10 | when: ansible_os_family == "RedHat" 11 | 12 | - name: uninstall httpd 13 | yum: 14 | name: httpd 15 | state: removed 16 | when: ansible_os_family == "RedHat" 17 | 18 | - name: stop apache2 services 19 | service: 20 | name: apache2 21 | state: stopped 22 | when: ansible_os_family == "Debian" 23 | 24 | - name: uninstall apache2 25 | apt: 26 | name: apache2 27 | state: absent 28 | when: ansible_os_family == "Debian" 29 | 30 | -------------------------------------------------------------------------------- /user.yml: -------------------------------------------------------------------------------- 1 | user: tom 2 | -------------------------------------------------------------------------------- /vault-pass.yml: -------------------------------------------------------------------------------- 1 | $ANSIBLE_VAULT;1.1;AES256 2 | 66643163656339343464623063636162383861333966656532323661626437393038333966626133 3 | 6261336161623931636137336631336536666338626631610a663030646665636665346533636433 4 | 65366234656264306262383838393632326230366465623035333036653736316539303363366131 5 | 6633626631336431610a653032326236653062373137626433376631373664663836376236353134 6 | 30633032323865666264613734393430613839386337343931336561363738346561 7 | --------------------------------------------------------------------------------