From 39fce93773b4f621489de69d373b38376acfce24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Tue, 27 Jan 2015 17:53:37 +0100 Subject: [PATCH] add a defined type for managing arbitrary python dotfiles python dotfiles are user-based ini-files. this defined type gives our users the ability to define arbitrary python related .dotfiles. (actually: arbitrary ini-files ;) This pr closes #87 --- README.md | 30 +++++++++++++++++++++ manifests/dotfile.pp | 61 +++++++++++++++++++++++++++++++++++++++++++ templates/inifile.erb | 8 ++++++ 3 files changed, 99 insertions(+) create mode 100644 manifests/dotfile.pp create mode 100644 templates/inifile.erb diff --git a/README.md b/README.md index 6dded52a..7ae8e8ed 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,36 @@ Manages Gunicorn virtual hosts. } ``` +### python::dotfile + +Manages arbitrary python dotiles with a simple config hash. + +**ensure** - present/absent. Default: present + +**filename** - Default: $title + +**mode** - Default: 0644 + +**owner** - Default: root + +**group** - Default: root + +**config** Config hash. This will be expanded to an ini-file. Default: {} + +```puppet +python::dotfile { '/var/lib/jenkins/.pip/pip.conf': + ensure => present, + owner => 'jenkins', + group => 'jenkins', + config => { + 'global' => { + 'index-url => 'https://mypypi.acme.com/simple/' + 'extra-index-url => https://pypi.risedev.at/simple/ + } + } +} +``` + ## Authors [Sergey Stankevich](https://github.com/stankevich) diff --git a/manifests/dotfile.pp b/manifests/dotfile.pp new file mode 100644 index 00000000..5d5a9c98 --- /dev/null +++ b/manifests/dotfile.pp @@ -0,0 +1,61 @@ +# == Define: python::dotfile +# +# Manages any python dotfiles with a simple config hash. +# +# === Parameters +# +# [*ensure*] +# present|absent. Default: present +# +# [*filename*] +# Filename. Default: $title +# +# [*mode*] +# File mode. Default: 0644 +# +# [*owner*] +# [*group*] +# Owner/group. Default: `root`/`root` +# +# [*config*] +# Config hash. This will be expanded to an ini-file. Default: {} +# +# === Examples +# +# python::dotfile { '/var/lib/jenkins/.pip/pip.conf': +# ensure => present, +# owner => 'jenkins', +# group => 'jenkins', +# config => { +# 'global' => { +# 'index-url => 'https://mypypi.acme.com/simple/' +# 'extra-index-url => https://pypi.risedev.at/simple/ +# } +# } +# } +# +# +define python::dotfile ( + $ensure = 'present', + $filename = $title, + $owner = 'root', + $group = 'root', + $mode = '0644', + $config = {}, +) { + $parent_dir = dirname($filename) + + exec { "create ${title}'s parent dir": + command => "install -o ${owner} -g ${group} -d ${parent_dir}", + path => [ '/usr/bin', '/bin', '/usr/local/bin', ], + creates => $parent_dir, + } + + file { $filename: + ensure => $ensure, + owner => $owner, + group => $group, + content => template("${module_name}/inifile.erb"), + require => Exec["create ${title}'s parent dir"], + } +} diff --git a/templates/inifile.erb b/templates/inifile.erb new file mode 100644 index 00000000..47ae7138 --- /dev/null +++ b/templates/inifile.erb @@ -0,0 +1,8 @@ +# this file is managed by puppet +<%- @config.sort.map do |section,conf| -%> +[<%= section -%>] +<%- conf.sort.map do |key,value| -%> +<%= key %> = <%= value %> +<%- end -%> + +<%- end -%>