Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
61 changes: 61 additions & 0 deletions manifests/dotfile.pp
Original file line number Diff line number Diff line change
@@ -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"],
}
}
8 changes: 8 additions & 0 deletions templates/inifile.erb
Original file line number Diff line number Diff line change
@@ -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 -%>