forked from yankils/ansible_for_beginners
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dab0965
Showing
27 changed files
with
418 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# ansible_for_beginners |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: ansible palybook to test ansible vault | ||
hosts: all | ||
become: true | ||
vars_files: | ||
- vault-pass.yml | ||
tasks: | ||
- name: clone a repo | ||
git: | ||
repo: https://yankils:{{ password }}@github.com/yankils/vault.git | ||
dest: /opt/ansadmin/test-vault |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[defaults] | ||
inventory = /opt/ansible/hosts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: ansible playbook to copy a file | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: copy a file | ||
copy: | ||
src: /opt/ansible/index.html | ||
dest: /home/ansadmin | ||
mode: 0600 | ||
owner: john |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
- name: this playbook creates a file or dir | ||
hosts: all | ||
# become: true | ||
# gather_facts: no | ||
tasks: | ||
- name: creating a file | ||
file: | ||
path: /home/ansadmin/dir1 | ||
state: directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
- name: this playbook is to create user | ||
hosts: all | ||
become: true | ||
vars_files: | ||
- user.yml | ||
tasks: | ||
- name: creating user {{ user }} | ||
user: | ||
name: "{{ user }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[webservers] | ||
172.31.30.140 | ||
172.31.16.135 | ||
|
||
[appservers] | ||
172.31.16.135 | ||
|
||
[dbservers] | ||
172.31.27.43 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1> Welcome to Apache tomcat </h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
- name: install apache2 on ubuntu server | ||
hosts: dbservers | ||
become: true | ||
tasks: | ||
- name: install apache2 | ||
apt: | ||
name: apache2 | ||
state: present | ||
|
||
- name: start apache2 | ||
service: | ||
name: apache2 | ||
state: started |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
- name: this playbook install httpd | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: install package | ||
yum: | ||
name: httpd | ||
state: installed | ||
when: ansible_os_family == "RedHat" | ||
|
||
- name: start apache | ||
service: | ||
name: httpd | ||
state: started | ||
when: ansible_os_family == "RedHat" | ||
|
||
- name: install apache2 | ||
apt: | ||
name: apache2 | ||
state: present | ||
when: ansible_os_family == "Debian" | ||
|
||
- name: start apache2 | ||
service: | ||
name: apache2 | ||
state: started | ||
when: ansible_os_family == "Debian" | ||
|
||
- name: copy index.html | ||
copy: | ||
src: /opt/ansible/index.html | ||
dest: /var/www/html | ||
mode: 0666 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
- name: this playbook install httpd | ||
hosts: webservers | ||
become: true | ||
tasks: | ||
- name: install package | ||
yum: | ||
name: httpd | ||
state: installed | ||
notify: start apache | ||
|
||
handlers: | ||
- name: start apache | ||
service: | ||
name: httpd | ||
state: started | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
- name: this playbook install pacakges | ||
hosts: webservers | ||
become: true | ||
tasks: | ||
- name: install package | ||
yum: | ||
# name: ['git', 'make', 'gcc', 'wget', 'telnet', 'gzip'] | ||
name: "{{ item }}" | ||
state: installed | ||
with_items: | ||
- git | ||
- make | ||
- gcc | ||
- wget | ||
- telnet | ||
- gzip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abc123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- name: this playbook install httpd | ||
hosts: all | ||
become: true | ||
roles: | ||
- setup-apache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
language: python | ||
python: "2.7" | ||
|
||
# Use the new container infrastructure | ||
sudo: false | ||
|
||
# Install ansible | ||
addons: | ||
apt: | ||
packages: | ||
- python-pip | ||
|
||
install: | ||
# Install ansible | ||
- pip install ansible | ||
|
||
# Check ansible version | ||
- ansible --version | ||
|
||
# Create ansible.cfg with correct roles_path | ||
- printf '[defaults]\nroles_path=../' >ansible.cfg | ||
|
||
script: | ||
# Basic role syntax check | ||
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check | ||
|
||
notifications: | ||
webhooks: https://galaxy.ansible.com/api/v1/notifications/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Role Name | ||
========= | ||
|
||
A brief description of the role goes here. | ||
|
||
Requirements | ||
------------ | ||
|
||
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. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
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. | ||
|
||
Dependencies | ||
------------ | ||
|
||
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. | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: | ||
|
||
- hosts: servers | ||
roles: | ||
- { role: username.rolename, x: 42 } | ||
|
||
License | ||
------- | ||
|
||
BSD | ||
|
||
Author Information | ||
------------------ | ||
|
||
An optional section for the role authors to include contact information, or a website (HTML is not allowed). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# defaults file for setup-apache | ||
port: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1> Welcome to Apache tomcat </h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
# handlers file for setup-apache | ||
- name: start apache | ||
service: | ||
name: httpd | ||
state: started | ||
|
||
- name: start apache2 | ||
service: | ||
name: apache2 | ||
state: started | ||
|
||
- name: restart apache | ||
service: | ||
name: httpd | ||
state: restarted | ||
|
||
- name: restart apache2 | ||
service: | ||
name: apache2 | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
# tasks file for setup-apache | ||
- name: install package | ||
yum: | ||
name: httpd | ||
state: installed | ||
when: ansible_os_family == "RedHat" | ||
notify: start apache | ||
|
||
- name: install apache2 | ||
apt: | ||
name: apache2 | ||
state: present | ||
when: ansible_os_family == "Debian" | ||
notify: start apache2 | ||
|
||
- name: copy index.html | ||
copy: | ||
src: /opt/ansible/index.html | ||
dest: /var/www/html | ||
mode: 0666 | ||
|
||
- name: Ensure the default Apache port is {{ port }} | ||
lineinfile: | ||
path: /etc/httpd/conf/httpd.conf | ||
regexp: '^Listen ' | ||
insertafter: '^#Listen ' | ||
line: Listen {{ port }} | ||
when: ansible_os_family == "RedHat" | ||
notify: restart apache | ||
|
||
- name: Ensure the default Apache port is {{ port }} on ubuntu | ||
lineinfile: | ||
path: /etc/apache2/ports.conf | ||
regexp: '^Listen ' | ||
insertafter: "# /etc/apache2/sites-enabled/000-default.conf" | ||
line: Listen {{ port }} | ||
when: ansible_os_family == "Debian" | ||
notify: restart apache2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# vars file for setup-apache | ||
#port: 8082 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
- name: this playbook install httpd | ||
hosts: all | ||
become: true | ||
vars: | ||
port: 8082 | ||
tasks: | ||
- name: install package | ||
yum: | ||
name: httpd | ||
state: installed | ||
when: ansible_os_family == "RedHat" | ||
notify: start apache | ||
|
||
- name: install apache2 | ||
apt: | ||
name: apache2 | ||
state: present | ||
when: ansible_os_family == "Debian" | ||
notify: start apache2 | ||
|
||
- name: copy index.html | ||
copy: | ||
src: /opt/ansible/index.html | ||
dest: /var/www/html | ||
mode: 0666 | ||
|
||
- name: Ensure the default Apache port is {{ port }} | ||
lineinfile: | ||
path: /etc/httpd/conf/httpd.conf | ||
regexp: '^Listen ' | ||
insertafter: '^#Listen ' | ||
line: Listen {{ port }} | ||
when: ansible_os_family == "RedHat" | ||
notify: restart apache | ||
|
||
- name: Ensure the default Apache port is {{ port }} on ubuntu | ||
lineinfile: | ||
path: /etc/apache2/ports.conf | ||
regexp: '^Listen ' | ||
insertafter: "# /etc/apache2/sites-enabled/000-default.conf" | ||
line: Listen {{ port }} | ||
when: ansible_os_family == "Debian" | ||
notify: restart apache2 | ||
|
||
handlers: | ||
- name: start apache | ||
service: | ||
name: httpd | ||
state: started | ||
|
||
- name: start apache2 | ||
service: | ||
name: apache2 | ||
state: started | ||
|
||
- name: restart apache | ||
service: | ||
name: httpd | ||
state: restarted | ||
|
||
- name: restart apache2 | ||
service: | ||
name: apache2 | ||
state: restarted |
Oops, something went wrong.