Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
puppet-modules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nbits
Puppet
puppet-modules
Commits
c4a9d9a5
Commit
c4a9d9a5
authored
Apr 12, 2021
by
drebs
Browse files
Options
Downloads
Patches
Plain Diff
Only return roles that actually exist
parent
98c23ed0
No related branches found
No related tags found
1 merge request
!9
Add support for VPN
Pipeline
#57268
passed
Apr 13, 2021
Stage: check-code
Stage: tests
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+3
-0
3 additions, 0 deletions
.gitlab-ci.yml
profile/files/puppet/puppet_node_classifier
+33
-21
33 additions, 21 deletions
profile/files/puppet/puppet_node_classifier
with
36 additions
and
21 deletions
.gitlab-ci.yml
+
3
−
0
View file @
c4a9d9a5
...
...
@@ -33,5 +33,8 @@ compile-profiles:
enc-test
:
image
:
debian:stable
stage
:
tests
variables
:
ENV_DIR
:
'
/etc/puppet/code/environments'
script
:
-
'
for
env
in
production
development
staging;
do
mkdir
-p
${ENV_DIR}/${env};
ln
-sf
${CI_PROJECT_DIR}
${ENV_DIR}/${env}/modules;
done'
-
'
${CI_PROJECT_DIR}/profile/files/puppet/puppet_node_classifier
--run-tests'
This diff is collapsed.
Click to expand it.
profile/files/puppet/puppet_node_classifier
+
33
−
21
View file @
c4a9d9a5
...
...
@@ -9,8 +9,8 @@
#
# And returns the proper classes and environment accordingly:
#
# - Class role::ROLE
#
# - Class role::ROLE
, if that role actually exists in the manifests tree
#
for the respective environment.
#
# - ENV is optional: if it is a prefix of one of "production", "staging" or
# "development", then one of these is returned. If not, "production" is
...
...
@@ -32,6 +32,7 @@ fi
DEFAULT_ENV
=
'production'
ENVIRONMENTS
=
'production staging development'
ENVIRONMENTS_DIR
=
/etc/puppet/code/environments
get_environment
()
{
...
...
@@ -61,15 +62,21 @@ enc() {
regex
=
"([[:alnum:]_]+)-([[:alnum:]_]+)(-([[:alnum:]_]+))?((
\.
[[:alnum:]_-]+)?)+$"
fqdn
=
${
1
}
# we're only interested in matching FQDNs
# we're only interested in matching FQDNs
that match the regular expression
if
[[
!
${
fqdn
}
=
~
${
regex
}
]]
;
then
echo
"classes:"
exit
0
fi
environment
=
$(
get_environment
${
BASH_REMATCH
[4]
}
)
role_candidate
=
${
BASH_REMATCH
[1]
}
role
=
$(
ls
-1
${
ENVIRONMENTS_DIR
}
/
${
environment
}
/modules/role/manifests |
sed
-e
s/
\\
.pp
\$
// |
grep
"^
${
role_candidate
}
\$
"
)
echo
"classes:"
echo
" - role::
${
BASH_REMATCH
[1]
}
"
echo
"environment:
$(
get_environment
${
BASH_REMATCH
[4]
}
)
"
if
[
-n
"
${
role
}
"
]
;
then
echo
" - role::
${
role
}
"
fi
echo
"environment:
${
environment
}
"
}
run_tests
()
{
...
...
@@ -96,35 +103,40 @@ run_tests() {
# Test uses of environment prefixes.
output
=
$(
enc
otherrole
-some_tag-prod.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
otherrole
\n
environment: production'
]
||
exit
1
output
=
$(
enc
server
-some_tag-prod.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
server
\n
environment: production'
]
||
exit
1
output
=
$(
enc
thirdrole
-some_tag-stag.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
thirdrole
\n
environment: staging'
]
||
exit
1
output
=
$(
enc
puppetserver
-some_tag-stag.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
puppetserver
\n
environment: staging'
]
||
exit
1
output
=
$(
enc
yetanotherrole
-some_tag-dev.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
yetanotherrole
\n
environment: development'
]
||
exit
1
output
=
$(
enc
webserver
-some_tag-dev.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
webserver
\n
environment: development'
]
||
exit
1
# Test uses of full environment names.
output
=
$(
enc
otherrole
-some_tag-production.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
otherrole
\n
environment: production'
]
||
exit
1
output
=
$(
enc
server
-some_tag-production.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
server
\n
environment: production'
]
||
exit
1
output
=
$(
enc
thirdrole
-some_tag-staging.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
thirdrole
\n
environment: staging'
]
||
exit
1
output
=
$(
enc
puppetserver
-some_tag-staging.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
puppetserver
\n
environment: staging'
]
||
exit
1
output
=
$(
enc
yetanotherrole
-some_tag-development.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
yetanotherrole
\n
environment: development'
]
||
exit
1
output
=
$(
enc
webserver
-some_tag-development.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::
webserver
\n
environment: development'
]
||
exit
1
# Test using an arbitrary environment
output
=
$(
enc s
omerole
-some_tag-someenv.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::s
omerole
\n
environment: production'
]
||
exit
1
output
=
$(
enc s
erver
-some_tag-someenv.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::s
erver
\n
environment: production'
]
||
exit
1
# Test default production environment when not present in hostname
output
=
$(
enc somerole-some_tag.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::somerole
\n
environment: production'
]
||
exit
1
output
=
$(
enc server-some_tag.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
- role::server
\n
environment: production'
]
||
exit
1
# Test using a role that doesn't exist
output
=
$(
enc idontexist-some_tag-prod.arbitraryfqdn.example.com
)
[
"
${
output
}
"
==
$'classes:
\n
environment: production'
]
||
exit
1
# Test using something that doesn't match ROLE-TAG[-ENV].DOMAIN
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment