1
0
Fork 0
mirror of synced 2024-12-29 01:53:21 -05:00
ultimate-vim/sources_non_forked/vim-snippets/UltiSnips/puppet.snippets

261 lines
6.8 KiB
Text
Raw Normal View History

priority -50
2012-08-16 23:41:25 -04:00
#########################################################################
# Python helper code #
#########################################################################
global !p
import vim
import os.path
def get_module_namespace_and_basename():
2021-05-05 04:25:00 -04:00
"""This function will try to guess the current class, define or type
name you are trying to create. Note that for this to work you should be
using the module structure as per the style guide. Examples inputs and
it's output
* /home/nikolavp/puppet/modules/collectd/manifests/init.pp -> collectd
2021-05-05 04:25:00 -04:00
* /home/nikolavp/puppet/modules/collectd/manifests/mysql.pp -> collectd::mysql
* /home/nikolavp/puppet/modules/collectd/types/dbname.pp -> Collectd::Dbname
"""
first_time = True
current_file_path_without_ext = vim.eval('expand("%:p:r")') or ""
if not current_file_path_without_ext:
return "name"
parts = os.path.split(current_file_path_without_ext)
namespace = ''
while parts[0] and parts[0] != '/':
if parts[1] == 'init' and first_time and not namespace:
first_time = False
parts = os.path.split(parts[0])
continue
2021-05-05 04:25:00 -04:00
if parts[1] in ['manifests', 'types']:
parsed_name = os.path.split(
parts[0])[1] + ('::' + namespace).rstrip(':')
if parts[1] == 'types':
parsed_name = parsed_name.title()
return parsed_name
else:
namespace = parts[1] + '::' + namespace
parts = os.path.split(parts[0])
# couldn't guess the namespace. The user is editing a raw file in no module like the site.pp file
return "name"
endglobal
###############################################################################
# Puppet Language Constructs #
# See http://docs.puppetlabs.com/puppet/latest/reference/lang_summary.html #
###############################################################################
snippet class "Class declaration" b
class ${1:`!p snip.rv = get_module_namespace_and_basename()`} {
${0:# body}
2012-08-16 23:41:25 -04:00
}
endsnippet
snippet define "Definition" b
define ${1:`!p snip.rv = get_module_namespace_and_basename()`} {
${0:# body}
2012-08-16 23:41:25 -04:00
}
endsnippet
2021-05-05 04:25:00 -04:00
snippet type "Data type alias" b
type ${1:`!p snip.rv = get_module_namespace_and_basename()`} = ${2:Type}
endsnippet
snippet lambda "Lambda function chain-called on a variable"
$${1:varname}.${2:each} |${3:Type} $${4:param}| {
$0
}
endsnippet
#################################################################
# Puppet Types #
# See http://docs.puppetlabs.com/references/latest/type.html #
#################################################################
snippet cron "Cron resource type" b
cron { '${1:name}':
user => ${2:user},
command => '${3:command}',
minute => ${3:minute},
hour => ${4:hour},
}
endsnippet
snippet exec "Exec resource type" b
exec { '${1:command}':
2019-12-30 08:28:38 -05:00
command => "${2:$1}",
user => "${3:root}",
2012-08-16 23:41:25 -04:00
}
endsnippet
snippet file "File resource type" b
file { '${1:name}':
source => "puppet://${2:path}",
mode => ${3:mode},
}
2012-08-16 23:41:25 -04:00
endsnippet
snippet File "Defaults for file" b
File {
owner => ${1:username},
group => ${2:groupname},
}
2012-08-16 23:41:25 -04:00
endsnippet
snippet group "Group resource type" b
group { '${1:groupname}':
ensure => ${3:present},
gid => ${2:gid},
}
2012-08-16 23:41:25 -04:00
endsnippet
snippet mount "Mount resource type" b
mount { '${1:path}':
device => '${2:/dev}',
fstype => '${3:filesystem}',
ensure => mounted,
options => 'rw,errors=remount-ro',
2012-08-16 23:41:25 -04:00
}
endsnippet
snippet package "Package resource type" b
package { '${1:name}':
ensure => ${2:installed},
2012-08-16 23:41:25 -04:00
}
endsnippet
snippet user "user resource type" b
user { '${1:username}':
ensure => ${2:present},
uid => ${3:uid},
gid => ${4:gid},
comment => ${5:gecos},
home => ${6:homedirectory},
managehome => false,
require => Group['${7:group'}],
2012-08-16 23:41:25 -04:00
}
endsnippet
snippet service "Service resource type" b
service { '${1:name}':
hasstatus => true,
enable => true,
ensure => running,
2012-08-16 23:41:25 -04:00
}
endsnippet
########################################################################
# Puppet Functions #
# See http://docs.puppetlabs.com/references/latest/function.html #
########################################################################
snippet alert "Alert Function" b
2017-02-11 08:01:38 -05:00
alert("${1:message}")$0
endsnippet
snippet crit "Crit Function" b
2017-02-11 08:01:38 -05:00
crit("${1:message}")$0
endsnippet
snippet debug "Debug Function" b
2017-02-11 08:01:38 -05:00
debug("${1:message}")$0
endsnippet
snippet defined "Defined Function" b
2017-02-11 08:01:38 -05:00
defined(${1:Resource}["${2:name}"])$0
endsnippet
snippet emerg "Emerg Function" b
2017-02-11 08:01:38 -05:00
emerg("${1:message}")$0
endsnippet
snippet extlookup "Simple Extlookup" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = extlookup("${2:Lookup}")$0
endsnippet
snippet extlookup "Extlookup with defaults" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = extlookup("${2:Lookup}", ${3:Default})$0
endsnippet
snippet extlookup "Extlookup with defaults and custom data file" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = extlookup("${2:Lookup}", ${3:Default}, ${4:Data Source})$0
endsnippet
snippet fail "Fail Function" b
2017-02-11 08:01:38 -05:00
fail("${1:message}")$0
endsnippet
snippet hiera "Hiera Function" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = hiera("${2:Lookup}")$0
endsnippet
snippet hiera "Hiera with defaults" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = hiera("${2:Lookup}", ${3:Default})$0
endsnippet
snippet hiera "Hiera with defaults and override" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = hiera("${2:Lookup}", ${3:Default}, ${4:Override})$0
endsnippet
snippet hiera_hash "Hiera Hash Function" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = hiera_hash("${2:Lookup}")$0
endsnippet
snippet hiera_hash "Hiera Hash with defaults" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = hiera_hash("${2:Lookup}", ${3:Default})$0
endsnippet
snippet hiera_hash "Hiera Hash with defaults and override" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = hiera_hash("${2:Lookup}", ${3:Default}, ${4:Override})$0
endsnippet
snippet hiera_include "Hiera Include Function" b
2017-02-11 08:01:38 -05:00
hiera_include("${1:Lookup}")$0
endsnippet
2021-05-05 04:25:00 -04:00
snippet lookup "Lookup data from hiera"
$${1:varname} = lookup('${2:hiera::key}')$0
endsnippet
snippet trocla "Lookup or generate sensitive information"
trocla('${1:lookup_key}', '${2:plain}', ${3:'length: 32'})$0
endsnippet
snippet include "Include Function" b
2017-02-11 08:01:38 -05:00
include ${1:classname}$0
endsnippet
snippet info "Info Function" b
2017-02-11 08:01:38 -05:00
info("${1:message}")$0
endsnippet
snippet inline_template "Inline Template Function" b
2017-02-11 08:01:38 -05:00
inline_template("<%= ${1:template} %>")$0
endsnippet
snippet notice "Notice Function" b
2017-02-11 08:01:38 -05:00
notice("${1:message}")$0
endsnippet
snippet realize "Realize Function" b
2017-02-11 08:01:38 -05:00
realize(${1:Resource}["${2:name}"])$0
endsnippet
snippet regsubst "Regsubst Function" b
2017-02-11 08:01:38 -05:00
regsubst($${1:Target}, '${2:regexp}', '${3:replacement}')$0
endsnippet
snippet split "Split Function" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = split($${1:Target}, '${2:regexp}')$0
endsnippet
snippet versioncmp "Version Compare Function" b
2017-02-11 08:01:38 -05:00
$${1:Variable} = versioncmp('${1:version}', '${2:version}')$0
endsnippet
snippet warning "Warning Function" b
2017-02-11 08:01:38 -05:00
warning("${1:message}")$0
endsnippet
2012-08-16 23:41:25 -04:00
# vim:ft=snippets: