Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F58996702
deploy.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Apr 19, 00:26
Size
1 KB
Mime Type
text/x-python
Expires
Sun, Apr 21, 00:26 (2 d)
Engine
blob
Format
Raw Data
Handle
17100803
Attached To
rSCMINICLUSTER SCITAS Mini Cluster
deploy.py
View Options
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
import
argparse
,
argcomplete
import
subprocess
,
re
ANSIBLE
=
"/usr/local/bin/ansible-playbook"
BOOK
=
"main.yml"
HOSTS
=
"hosts"
TAGS
=
[]
TAGS_LIST
=
[]
#
# PREPARE
#
list_tags
=
str
(
subprocess
.
check_output
([
ANSIBLE
,
'-i'
,
HOSTS
,
'--list-tags'
,
BOOK
]))
regex
=
re
.
compile
(
'\[([a-z, ]+)\]'
,
re
.
MULTILINE
)
find_tags
=
re
.
findall
(
regex
,
list_tags
)
clean_tags
=
set
()
for
t
in
find_tags
:
clean_tags
.
update
(
t
.
split
(
', '
))
TAGS_LIST
=
list
(
clean_tags
)
#
# ARGS
#
parser
=
argparse
.
ArgumentParser
(
formatter_class
=
argparse
.
RawDescriptionHelpFormatter
,
description
=
'''Ansible deploy script for Toy Cluser'''
,
epilog
=
'''
Examples:
./deploy.py
./deploy.py -t beegfs
./deploy.py --tags packages ssh
'''
)
parser
.
add_argument
(
'-t'
,
'--tags'
,
choices
=
TAGS_LIST
,
nargs
=
'+'
)
parser
.
set_defaults
(
tags
=
[])
argcomplete
.
autocomplete
(
parser
)
args
=
parser
.
parse_args
()
TAGS
=
args
.
tags
#
# MAIN
#
command
=
[
ANSIBLE
,
'--inventory-file'
,
HOSTS
]
if
len
(
TAGS
)
>
0
:
command
.
extend
([
'--tags'
,
','
.
join
(
TAGS
)])
command
.
extend
([
BOOK
])
print
(
' '
.
join
(
command
)
+
'
\n
'
)
subprocess
.
call
(
command
)
Event Timeline
Log In to Comment