Skip to content

Commit ad0072b

Browse files
author
Alexis von Glasow
committed
Initial import
0 parents  commit ad0072b

12 files changed

Lines changed: 437 additions & 0 deletions

File tree

.travis.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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/

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Ansible-cloudflare
2+
=========
3+
4+
Install mod_cloudflare for apache or configure NGINX to get real IP when using cloudflare.
5+
6+
## Apache
7+
8+
This role will download, compile and install
9+
[mod_cloudflare](https://github.com/cloudflare/mod_cloudflare.git) for apache
10+
more information on [cloudflare website](https://support.cloudflare.com/hc/en-us/articles/203656534-How-do-I-restore-original-visitor-IP-with-Apache-2-4-)
11+
12+
## Nginx
13+
14+
This role will add configuration file into `/etc/nginx/conf.d/` to ensure all
15+
IP's from cloudflare are set and configured to use real IP more information
16+
on [cloudflare website](https://support.cloudflare.com/hc/en-us/articles/200170706-How-do-I-restore-original-visitor-IP-with-Nginx-)
17+
18+
Requirements
19+
------------
20+
21+
Installed apache2 or nginx
22+
23+
Role Variables
24+
--------------
25+
26+
ansible_cloudflare_server: should be "apache2" or "nginx" depending on which server you have installed on you machine
27+
28+
Dependencies
29+
------------
30+
31+
No dependencies
32+
33+
Example Playbook
34+
----------------
35+
36+
### Apache
37+
38+
- hosts: servers
39+
roles:
40+
- { role: ansible-cloudflare, ansible_cloudflare_server: apache2 }
41+
42+
### Nginx
43+
44+
- hosts: servers
45+
roles:
46+
- { role: ansible-cloudflare, ansible_cloudflare_server: nginx }
47+
48+
License
49+
-------
50+
51+
BSD
52+
53+
Author Information
54+
------------------
55+
56+
Created by [Alexis von Glasow](https://github.com/vonglasow) for [Inovia](https://github.com/inovia-team)

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
# defaults file for ansible-cloudflare
3+
ansible_cloudflare_server: ""

handlers/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# handlers file for ansible-cloudflare
3+
- name: reload server
4+
service:
5+
name: "{{ ansible_cloudflare_server }}"
6+
state: reloaded
7+
become: yes
8+

meta/main.yml

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
galaxy_info:
2+
author: Alexis von Glasow
3+
description: Install mod_cloudflare for apache and configure header for NGINX
4+
company: Inovia
5+
6+
# If the issue tracker for your role is not on github, uncomment the
7+
# next line and provide a value
8+
# issue_tracker_url: http://example.com/issue/tracker
9+
10+
# Some suggested licenses:
11+
# - BSD (default)
12+
# - MIT
13+
# - GPLv2
14+
# - GPLv3
15+
# - Apache
16+
# - CC-BY
17+
license: BSD
18+
19+
min_ansible_version: 2.0
20+
21+
# Optionally specify the branch Galaxy will use when accessing the GitHub
22+
# repo for this role. During role install, if no tags are available,
23+
# Galaxy will use this branch. During import Galaxy will access files on
24+
# this branch. If travis integration is cofigured, only notification for this
25+
# branch will be accepted. Otherwise, in all cases, the repo's default branch
26+
# (usually master) will be used.
27+
#github_branch:
28+
29+
#
30+
# Below are all platforms currently available. Just uncomment
31+
# the ones that apply to your role. If you don't see your
32+
# platform on this list, let us know and we'll get it added!
33+
#
34+
platforms:
35+
#- name: OpenBSD
36+
# versions:
37+
# - all
38+
# - 5.6
39+
# - 5.7
40+
# - 5.8
41+
# - 5.9
42+
# - 6.0
43+
#- name: Fedora
44+
# versions:
45+
# - all
46+
# - 16
47+
# - 17
48+
# - 18
49+
# - 19
50+
# - 20
51+
# - 21
52+
# - 22
53+
# - 23
54+
# - 24
55+
# - 25
56+
#- name: DellOS
57+
# versions:
58+
# - all
59+
# - 10
60+
# - 6
61+
# - 9
62+
#- name: MacOSX
63+
# versions:
64+
# - all
65+
# - 10.10
66+
# - 10.11
67+
# - 10.12
68+
# - 10.7
69+
# - 10.8
70+
# - 10.9
71+
#- name: Synology
72+
# versions:
73+
# - all
74+
# - any
75+
#- name: Junos
76+
# versions:
77+
# - all
78+
# - any
79+
#- name: GenericBSD
80+
# versions:
81+
# - all
82+
# - any
83+
#- name: Void Linux
84+
# versions:
85+
# - all
86+
# - any
87+
#- name: GenericLinux
88+
# versions:
89+
# - all
90+
# - any
91+
#- name: NXOS
92+
# versions:
93+
# - all
94+
# - any
95+
#- name: IOS
96+
# versions:
97+
# - all
98+
# - any
99+
#- name: Amazon
100+
# versions:
101+
# - all
102+
# - 2013.03
103+
# - 2013.09
104+
# - 2016.03
105+
# - 2016.09
106+
#- name: ArchLinux
107+
# versions:
108+
# - all
109+
# - any
110+
#- name: FreeBSD
111+
# versions:
112+
# - all
113+
# - 10.0
114+
# - 10.1
115+
# - 10.2
116+
# - 10.3
117+
# - 11.0
118+
# - 8.0
119+
# - 8.1
120+
# - 8.2
121+
# - 8.3
122+
# - 8.4
123+
# - 9.0
124+
# - 9.1
125+
# - 9.1
126+
# - 9.2
127+
# - 9.3
128+
- name: Ubuntu
129+
versions:
130+
# - all
131+
# - lucid
132+
# - maverick
133+
# - natty
134+
# - oneiric
135+
# - precise
136+
# - quantal
137+
# - raring
138+
# - saucy
139+
- trusty
140+
- utopic
141+
- vivid
142+
- wily
143+
- xenial
144+
# - yakkety
145+
#- name: Debian
146+
# versions:
147+
# - all
148+
# - etch
149+
# - jessie
150+
# - lenny
151+
# - sid
152+
# - squeeze
153+
# - stretch
154+
# - wheezy
155+
#- name: Alpine
156+
# versions:
157+
# - all
158+
# - any
159+
#- name: EL
160+
# versions:
161+
# - all
162+
# - 5
163+
# - 6
164+
# - 7
165+
#- name: Windows
166+
# versions:
167+
# - all
168+
# - 2012R2
169+
#- name: SmartOS
170+
# versions:
171+
# - all
172+
# - any
173+
#- name: opensuse
174+
# versions:
175+
# - all
176+
# - 12.1
177+
# - 12.2
178+
# - 12.3
179+
# - 13.1
180+
# - 13.2
181+
#- name: SLES
182+
# versions:
183+
# - all
184+
# - 10SP3
185+
# - 10SP4
186+
# - 11
187+
# - 11SP1
188+
# - 11SP2
189+
# - 11SP3
190+
# - 11SP4
191+
# - 12
192+
# - 12SP1
193+
#- name: GenericUNIX
194+
# versions:
195+
# - all
196+
# - any
197+
#- name: Solaris
198+
# versions:
199+
# - all
200+
# - 10
201+
# - 11.0
202+
# - 11.1
203+
# - 11.2
204+
# - 11.3
205+
#- name: eos
206+
# versions:
207+
# - all
208+
# - Any
209+
210+
galaxy_tags:
211+
- cloudflare
212+
- mod
213+
- apache
214+
- nginx
215+
- cloud
216+
- web
217+
- config
218+
# List tags for your role here, one per line. A tag is
219+
# a keyword that describes and categorizes the role.
220+
# Users find roles by searching for tags. Be sure to
221+
# remove the '[]' above if you add tags to this list.
222+
#
223+
# NOTE: A tag is limited to a single word comprised of
224+
# alphanumeric characters. Maximum 20 tags per role.
225+
226+
dependencies: []
227+
# List your role dependencies here, one per line.
228+
# Be sure to remove the '[]' above if you add dependencies
229+
# to this list.

tasks/apache2.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
##
3+
# Cloudflare Apache
4+
##
5+
- name: "Register if module already loaded"
6+
shell: "/usr/sbin/apache2ctl -M | grep cloudflare"
7+
register: mod_cloudflare
8+
failed_when: false
9+
changed_when: false
10+
tags:
11+
- cloudflare
12+
13+
- name: "Register if module is already compiled and available"
14+
shell: "ls /etc/apache2/mods-available | grep cloudflare"
15+
register: is_mod_cloudflare_available
16+
failed_when: false
17+
changed_when: false
18+
tags:
19+
- cloudflare
20+
21+
- name: "Be sure package for compile and enabled mod are installed"
22+
apt: name={{item}} state=present update_cache=yes cache_valid_time=3600
23+
become: yes
24+
with_items:
25+
- libtool
26+
- apache2-dev
27+
when: mod_cloudflare|failed and is_mod_cloudflare_available|failed
28+
tags:
29+
- cloudflare
30+
31+
- name: "Clone source code from github cloudflare organization"
32+
git:
33+
repo: https://github.com/cloudflare/mod_cloudflare.git
34+
dest: /tmp/mod_cloudflare
35+
when: mod_cloudflare|failed and is_mod_cloudflare_available|failed
36+
tags:
37+
- cloudflare
38+
39+
- name: "Create apache mod"
40+
shell: "apxs -a -i -c mod_cloudflare.c"
41+
become: yes
42+
args:
43+
chdir: /tmp/mod_cloudflare
44+
when: mod_cloudflare|failed and is_mod_cloudflare_available|failed
45+
notify: reload server
46+
tags:
47+
- cloudflare
48+
49+
- name: "Enable apache mod if already available"
50+
apache2_module:
51+
state: present
52+
name: cloudflare
53+
notify: reload server
54+
when: is_mod_cloudflare_available and mod_cloudflare|failed
55+
tags:
56+
- cloudflare
57+
58+
- name: "Clean folders"
59+
file:
60+
path: /tmp/mod_cloudflare
61+
state: absent
62+
when: mod_cloudflare|failed and is_mod_cloudflare_available|failed
63+
tags:
64+
- cloudflare
65+

0 commit comments

Comments
 (0)