Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3938586
generate-webcontent-index.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
generate-webcontent-index.py
View Options
#!/usr/bin/env python3
# -------------------------------------------------------------
# rOPS — regenerate roles/webserver-content/init.sls
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2017-11-24
# Description: Read the web_content_sls pillar entry
# and regenerate the webserver-content include.
# License: BSD-2-Clause
# -------------------------------------------------------------
import
yaml
# -------------------------------------------------------------
# Table of contents
# -------------------------------------------------------------
#
# :: Configuration
# :: Update code
# :: Run task
#
# -------------------------------------------------------------
# -------------------------------------------------------------
# Configuration
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pillar_file
=
"pillar/webserver/sites.sls"
file_to_update
=
"roles/webserver-content/init.sls"
# -------------------------------------------------------------
# Update code
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
do_update
(
pillar_file
,
file_to_update
):
print_header
(
file_to_update
)
print
(
"
\n
include:"
)
for
site
in
get_sites
(
pillar_file
):
print
(
" - {}"
.
format
(
site
))
def
get_pillar_entry
(
pillar_file
,
key
):
with
open
(
pillar_file
)
as
fd
:
pillar
=
yaml
.
load
(
fd
.
read
())
return
pillar
[
key
]
def
get_sites
(
pillar_file
):
sites
=
get_pillar_entry
(
pillar_file
,
'web_content_sls'
)
return
sorted
([
site
for
sublist
in
[
sites
[
role
]
for
role
in
sites
]
for
site
in
sublist
])
def
print_header
(
file_to_update
):
with
open
(
file_to_update
)
as
fd
:
for
line
in
fd
:
if
not
line
.
startswith
(
"#"
):
break
print
(
line
,
end
=
""
)
# -------------------------------------------------------------
# Run task
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
__name__
==
"__main__"
:
do_update
(
pillar_file
,
file_to_update
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, Dec 26, 03:23 (19 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2282111
Default Alt Text
generate-webcontent-index.py (2 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment