Skip to content

Commit

Permalink
ansible for beginners
Browse files Browse the repository at this point in the history
  • Loading branch information
yankils committed Dec 30, 2019
0 parents commit dab0965
Show file tree
Hide file tree
Showing 27 changed files with 418 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ansible_for_beginners
11 changes: 11 additions & 0 deletions ansible-vault.yml
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
3 changes: 3 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[defaults]
inventory = /opt/ansible/hosts

11 changes: 11 additions & 0 deletions copy_file.yml
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
10 changes: 10 additions & 0 deletions create_file.yml
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
10 changes: 10 additions & 0 deletions create_user.yml
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 }}"
9 changes: 9 additions & 0 deletions hosts
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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1> Welcome to Apache tomcat </h1>
14 changes: 14 additions & 0 deletions install_apache2.yml
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
34 changes: 34 additions & 0 deletions install_apache_httpd.yml
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
17 changes: 17 additions & 0 deletions install_httpd.yml
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

17 changes: 17 additions & 0 deletions install_packages.yml
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
1 change: 1 addition & 0 deletions pass.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abc123
6 changes: 6 additions & 0 deletions setup-apache.yml
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
29 changes: 29 additions & 0 deletions setup-apache/.travis.yml
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/
38 changes: 38 additions & 0 deletions setup-apache/README.md
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).
3 changes: 3 additions & 0 deletions setup-apache/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# defaults file for setup-apache
port: 8080
1 change: 1 addition & 0 deletions setup-apache/files/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1> Welcome to Apache tomcat </h1>
21 changes: 21 additions & 0 deletions setup-apache/handlers/main.yml
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
39 changes: 39 additions & 0 deletions setup-apache/tasks/main.yml
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
3 changes: 3 additions & 0 deletions setup-apache/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# vars file for setup-apache
#port: 8082
65 changes: 65 additions & 0 deletions setup-apache_backup.yml
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
Loading

0 comments on commit dab0965

Please sign in to comment.