-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to configure xinetd services from pillar #1
base: master
Are you sure you want to change the base?
Changes from 7 commits
02862db
9f9ea67
472dcad
e2bb110
ae06a94
591bfdf
be97a97
37be9b3
95c9706
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.kitchen/ | ||
Gemfile.lock |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<% | ||
require 'socket' | ||
|
||
# @return [String] public IP address of workstation used for egress traffic | ||
def local_ip | ||
@local_ip ||= begin | ||
# turn off reverse DNS resolution temporarily | ||
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true | ||
|
||
UDPSocket.open do |s| | ||
s.connect '64.233.187.99', 1 # a google IP, does not hit network | ||
s.addr.last | ||
end | ||
ensure | ||
Socket.do_not_reverse_lookup = orig | ||
end | ||
end | ||
|
||
# @return [Integer] default polipo listening port | ||
def local_port ; 8123 ; end | ||
|
||
# @return [String] the polipo proxy URL | ||
def http_proxy_url ; "http://#{local_ip}:#{local_port}" ; end | ||
|
||
# @return [TrueClass,FalseClass] whether or not the polipo port is listening | ||
def proxy_running? | ||
socket = TCPSocket.new(local_ip, local_port) | ||
true | ||
rescue SocketError, Errno::ECONNREFUSED, | ||
Errno::EHOSTUNREACH, Errno::ENETUNREACH, IOError | ||
false | ||
rescue Errno::EPERM, Errno::ETIMEDOUT | ||
false | ||
ensure | ||
socket && socket.close | ||
end | ||
%> | ||
--- | ||
driver: | ||
name: docker | ||
use_sudo: true | ||
require_chef_omnibus: false | ||
<% if proxy_running? %> | ||
http_proxy: <%= http_proxy_url %> | ||
https_proxy: <%= http_proxy_url %> | ||
<% end %> | ||
|
||
driver_config: | ||
provision_command: | ||
- sed -i 's/http\:\/\/archive/http\:\/\/us.archive/g' /etc/apt/sources.list | ||
- apt-get clean && rm -rf /var/lib/apt/lists/* && apt-get update | ||
<% if proxy_running? %> | ||
- echo 'Acquire::http::Proxy "<%= http_proxy_url %>";' > /etc/apt/apt.conf.d/proxy | ||
- "env http_proxy=<%= http_proxy_url %> bash -c 'curl -sL http://www.chef.io/chef/install.sh | bash'" | ||
- curl -o bootstrap-salt.sh -sL https://bootstrap.saltstack.com | ||
- env http_proxy=<%= http_proxy_url %> bash bootstrap-salt.sh -X -d -H <%= http_proxy_url %> | ||
<% else %> | ||
- "curl -sL http://www.chef.io/chef/install.sh | bash" | ||
- curl -o bootstrap-salt.sh -sL https://bootstrap.saltstack.com | ||
- bash bootstrap-salt.sh -X -d | ||
<% end %> | ||
|
||
provisioner: | ||
# installs from an http:// source to enable better caching through | ||
# http_proxy, and yes, this is a bit evil | ||
<% if proxy_running? %> | ||
http_proxy: <%= http_proxy_url %> | ||
https_proxy: <%= http_proxy_url %> | ||
chef_omnibus_url: http://www.chef.io/chef/install.sh | ||
chef_bootstrap_url: http://www.chef.io/chef/install.sh | ||
additional_minion_config: | ||
proxy_host: <%= (http_proxy_url.split(":")[1]).split("/")[2] %> | ||
proxy_port: <%= http_proxy_url.split(":")[2] %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<% | ||
require 'yaml' | ||
formula = YAML.load_file('FORMULA') | ||
formula_name = formula['name'] | ||
%> | ||
--- | ||
platforms: | ||
- name: ubuntu-16.04 | ||
- name: ubuntu-18.04 | ||
|
||
provisioner: | ||
name: salt_solo | ||
salt_install: bootstrap | ||
salt_bootstrap_url: https://bootstrap.saltstack.com | ||
salt_version: latest | ||
pillars-from-files: | ||
<%= formula_name %>.sls: pillar.example | ||
pillars: | ||
top.sls: | ||
base: | ||
'*': | ||
- <%= formula_name %> | ||
log_level: <%= ENV['SALT_DEBUG_LEVEL'] || 'debug' %> | ||
formula: <%= formula_name %> | ||
state_top: | ||
base: | ||
'*': | ||
- <%= formula_name %> | ||
|
||
suites: | ||
- name: default |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
language: ruby | ||
|
||
rvm: | ||
- 2.4.1 | ||
|
||
sudo: required | ||
services: docker | ||
|
||
env: | ||
matrix: | ||
- INSTANCE=default-ubuntu-1604 | ||
- INSTANCE=default-ubuntu-1804 | ||
|
||
# https://github.com/zuazo/kitchen-in-travis-native/issues/1#issuecomment-142455888 | ||
before_script: sudo iptables -L DOCKER || sudo iptables -N DOCKER | ||
|
||
install: | ||
# setup ci for test formula | ||
- export BUNDLE_GEMFILE=$PWD/Gemfile | ||
- bundle install | ||
|
||
script: | ||
# Run unit tests | ||
- KITCHEN_LOCAL_YAML=.kitchen.docker.yml bundle exec kitchen test ${INSTANCE} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: xinetd | ||
os: Ubuntu | ||
os_family: Debian | ||
version: 201705 | ||
release: 1 | ||
minimum_version: 2016.11.4 | ||
summary: Formula for installing xinetd | ||
description: Formula for installing xinetd |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
source 'https://rubygems.org' | ||
|
||
ruby '2.4.1' | ||
|
||
gem "test-kitchen", '>=2.2.4' | ||
gem "kitchen-docker" | ||
gem "kitchen-salt" | ||
gem 'kitchen-inspec' | ||
gem "kitchen-vagrant" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,9 +15,13 @@ Available states | |||||
.. contents:: | ||||||
:local: | ||||||
|
||||||
``xinetd`` | ||||||
``xinetd.install`` | ||||||
---------- | ||||||
|
||||||
Installs the xinetd package and starts the daemon. | ||||||
|
||||||
|
||||||
``xinetd.config`` | ||||||
---------- | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Configure xinetd services based on pillar data. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
xinetd: | ||
services: | ||
# Configure custom xinetd services (Options are not checked) | ||
echo: | ||
description: An xinetd internal service which echo's characters back to | ||
# yes or no values needs to be escaped otherwise are treated as booleans | ||
disable: 'yes' | ||
type: INTERNAL | ||
id: echo-stream | ||
socket_type: stream | ||
protocol: tcp | ||
user: root | ||
# yes or no values needs to be escaped otherwise are treated as booleans | ||
wait: 'no' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'serverspec' | ||
|
||
# Required by serverspec | ||
set :backend, :exec | ||
|
||
describe "xinetd" do | ||
it "package is installed" do | ||
expect(package("xinetd")).to be_installed | ||
end | ||
|
||
it "service is enabled" do | ||
expect(service("xinetd")).to be_enabled | ||
end | ||
|
||
it "service is running" do | ||
expect(service("xinetd")).to be_running | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||||
{%- from "xinetd/map.jinja" import xinetd with context -%} | ||||||
|
||||||
{%- if xinetd.services is iterable %} | ||||||
{%- for service, config in xinetd.services.iteritems() %} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
xinetd_{{ service }}_config: | ||||||
file.managed: | ||||||
- name: /etc/xinetd.d/{{ service }} | ||||||
- source: salt://xinetd/files/config_template | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary for this PR but this is ripe for converting to TOFS (refer back to the |
||||||
- template: jinja | ||||||
- context: | ||||||
service: {{ service }} | ||||||
config: {{ config|tojson }} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Unfortunately, we can't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's also a second issue about using |
||||||
- watch_in: | ||||||
service: xinetd | ||||||
{% endfor %} | ||||||
{% endif %} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||
# ----------------------------------- | ||||||
# THIS FILE IS MANAGED BY SALTSTACK | ||||||
# MANUAL CHANGES WILL BE OVERRIDEN | ||||||
# ----------------------------------- | ||||||
{% if config.description is defined %} | ||||||
# description: {{ config.description }} | ||||||
{% endif -%} | ||||||
service {{ service }} | ||||||
{ | ||||||
{% for k, v in config.iteritems() -%} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{%- if k != 'description' -%} | ||||||
{{ '%-15s' | format(k) | indent(2, true) ~ ' = ' ~ v }} | ||||||
{% endif -%} | ||||||
{% endfor -%} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,3 @@ | ||
{%- from "xinetd/map.jinja" import xinetd with context -%} | ||
|
||
xinetd: | ||
pkg.installed: | ||
- name: {{ xinetd.pkg }} | ||
service.running: | ||
- name: {{ xinetd.service }} | ||
- enable: True | ||
|
||
# The following states are inert by default and can be used by other states to | ||
# trigger a restart or reload as needed. | ||
xinetd-reload: | ||
module.wait: | ||
- name: service.reload | ||
- m_name: {{ xinetd.service }} | ||
|
||
xinetd-restart: | ||
module.wait: | ||
- name: service.restart | ||
- m_name: {{ xinetd.service }} | ||
include: | ||
- xinetd.install | ||
- xinetd.config |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{%- from "xinetd/map.jinja" import xinetd with context -%} | ||
|
||
xinetd: | ||
pkg.installed: | ||
- name: {{ xinetd.pkg }} | ||
service.running: | ||
- name: {{ xinetd.service }} | ||
- enable: True | ||
|
||
# The following states are inert by default and can be used by other states to | ||
# trigger a restart or reload as needed. | ||
xinetd-reload: | ||
module.wait: | ||
- name: service.reload | ||
- m_name: {{ xinetd.service }} | ||
|
||
xinetd-restart: | ||
module.wait: | ||
- name: service.restart | ||
- m_name: {{ xinetd.service }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
{% set xinetd = { | ||
'pkg': 'xinetd', | ||
'service': 'xinetd', | ||
} %} | ||
{% set default_settings = salt['grains.filter_by']({ | ||
'default': { | ||
'pkg': 'xinetd', | ||
'service': 'xinetd', | ||
}, | ||
}, merge=salt['pillar.get']('xinetd:lookup')) %} | ||
|
||
{% set xinetd = salt['pillar.get']( | ||
'xinetd', | ||
default=default_settings, | ||
merge=True | ||
) | ||
%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.