Skip to content

Commit

Permalink
feat(apt_proxy): add apt_proxy role
Browse files Browse the repository at this point in the history
  • Loading branch information
donhector committed Dec 11, 2021
1 parent 2e25103 commit 31f347a
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 0 deletions.
35 changes: 35 additions & 0 deletions donhector/workstation/roles/apt_proxy/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# Based on ansible-lint config
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length:
max: 120
level: warning
new-line-at-end-of-file: enable
new-lines:
type: unix
trailing-spaces: disable
truthy: enable
34 changes: 34 additions & 0 deletions donhector/workstation/roles/apt_proxy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## only run the linter, no testing
.PHONY: lint
lint:
@molecule lint

## molecule test already does linting
.PHONY: test
test:
@molecule test --all

## Spin up an instance
.PHONY: create
create:
@molecule create

## Converge (run the playbook)
.PHONY: converge
converge: create
@molecule converge

## Log into the running instance
.PHONY: login
login:
@molecule login -h $1

## Destroy the instance
.PHONY: destroy
destroy:
@molecule destroy

.PHONY: run
## Run the playbook locally without molecule
run:
@ansible-playbook -v tests/test.yml -i tests/inventory
48 changes: 48 additions & 0 deletions donhector/workstation/roles/apt_proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apt_proxy
=========

Configure proxy settings for APT

Requirements
------------

None

Role Variables
--------------

`apt_proxy__filename` Filename to be used to store the proxy configuration
`apt_proxy__http_url`: HTTP proxy URL. Default is the remote value or empty
`apt_proxy__https_url`: HTTPS proxy URL. Default is the remote value or empty
`apt_proxy__ftp_url`: FTP proxy URL. Default is the remote value or empty

By default the role takes proxy settings found in the remote host and will use those in `apt_proxy__filename`.
If the user does not specify any custom values in those url variables above, then the role will check if proxy settings are found in the remote host environment. If they are not found, and the user did not specify custom ones, then the role won't create the `apt_proxy__filename`

Dependencies
------------

none

Example Playbook
----------------

```yaml
- hosts: servers
roles:
- role: donhector.apt_proxy
vars:
apt_proxy__http_url: http://user:pass@server.com:3128
apt_proxy__https_url: https://user:pass@server.com:3128
apt_proxy__ftp_url: ftp://user:pass@server.com:3128
```

License
-------

MIT

Author Information
------------------

github.com/donhector
7 changes: 7 additions & 0 deletions donhector/workstation/roles/apt_proxy/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# defaults file for apt_proxy

apt_proxy__filename: '99proxy.conf'
apt_proxy__http_url: '{{ ansible_env.http_proxy | default() }}'
apt_proxy__https_url: '{{ ansible_env.https_proxy | default() }}'
apt_proxy__ftp_url: '{{ ansible_env.ftp_proxy | default() }}'
2 changes: 2 additions & 0 deletions donhector/workstation/roles/apt_proxy/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for apt_proxy
26 changes: 26 additions & 0 deletions donhector/workstation/roles/apt_proxy/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
galaxy_info:
role_name: apt_proxy
description: apt proxy configuration settings
author: donhector
company: darkenv.com

license: MIT

min_ansible_version: 2.11

platforms:
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all

galaxy_tags:
- apt
- proxy
- ubuntu
- debian

dependencies: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Converge
hosts: all
roles:
- role: donhector.apt_proxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
dependency:
name: galaxy

driver:
name: docker

lint: |
set -e
yamllint .
ansible-lint
platforms:

- name: ubuntu2004
image: ${MOLECULE_DISTRO:-geerlingguy/docker-ubuntu2004-ansible:latest}
# Needed for systemd
command: ${MOLECULE_DOCKER_COMMAND:-/lib/systemd/systemd}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
capabilities:
- SYS_ADMIN
pre_build_image: true

- name: debian9
image: ${MOLECULE_DISTRO:-geerlingguy/docker-debian9-ansible:latest}
# Needed for systemd
command: ${MOLECULE_DOCKER_COMMAND:-/lib/systemd/systemd}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
capabilities:
- SYS_ADMIN
pre_build_image: true

- name: debian10
image: ${MOLECULE_DISTRO:-geerlingguy/docker-debian10-ansible:latest}
# Needed for systemd
command: ${MOLECULE_DOCKER_COMMAND:-/lib/systemd/systemd}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
capabilities:
- SYS_ADMIN
pre_build_image: true

- name: debian11
image: ${MOLECULE_DISTRO:-geerlingguy/docker-debian11-ansible:latest}
# Needed for systemd
command: ${MOLECULE_DOCKER_COMMAND:-/lib/systemd/systemd}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
capabilities:
- SYS_ADMIN
pre_build_image: true

provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}

verifier:
name: ansible
enabled: false
10 changes: 10 additions & 0 deletions donhector/workstation/roles/apt_proxy/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Example assertion
assert:
that: true
11 changes: 11 additions & 0 deletions donhector/workstation/roles/apt_proxy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# tasks file for apt_proxy

- name: Configure APT to use HTTP/HTTPS proxy
become: true
ansible.builtin.template:
src: 'proxy.conf.j2'
dest: '/etc/apt/apt.conf.d/{{ apt_proxy__filename }}'
mode: '0644'
when: ansible_os_family == 'Debian' and
(apt_proxy__http_url or apt_proxy__https_url or apt_proxy__ftp_url)
9 changes: 9 additions & 0 deletions donhector/workstation/roles/apt_proxy/templates/proxy.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% if apt_proxy__http_url %}
Acquire::http::Proxy "{{ apt_proxy__http_url }}";
{% endif %}
{% if apt_proxy__https_url %}
Acquire::https::Proxy "{{ apt_proxy__https_url }}";
{% endif %}
{% if apt_proxy__ftp_url %}
Acquire::ftp::Proxy "{{ apt_proxy__ftp_url }}";
{% endif %}
1 change: 1 addition & 0 deletions donhector/workstation/roles/apt_proxy/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
6 changes: 6 additions & 0 deletions donhector/workstation/roles/apt_proxy/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- hosts: localhost
vars:
ansible_connection: local
roles:
- { role: donhector.apt_proxy }
2 changes: 2 additions & 0 deletions donhector/workstation/roles/apt_proxy/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for apt_proxy

0 comments on commit 31f347a

Please sign in to comment.