Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65469129
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
Tue, Jun 4, 00:44
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Jun 6, 00:44 (2 d)
Engine
blob
Format
Raw Data
Handle
17210012
Attached To
rPHINFRA c4science
deploy.py
View Options
#!/usr/bin/env python2
# PYTHON_ARGCOMPLETE_OK
import
argparse
,
argcomplete
import
subprocess
ANSIBLE
=
"/usr/bin/ansible-playbook"
PROD_BOOK
=
"books/main_prod.yml"
PROD_HOST
=
"hosts-prod"
PROD_VARS
=
"../vars/main.yml"
TEST_BOOK
=
"books/main_test.yml"
TEST_HOST
=
"hosts-test"
TEST_VARS
=
"../vars/test.yml"
ANSIBLE_HOSTS
=
''
ANSIBLE_BOOK
=
''
ANSIBLE_TAGS
=
[]
ANSIBLE_SKIP
=
[]
ACTION
=
''
TYPE
=
''
ENV
=
'test'
ENV_LIST
=
[
'prod'
,
'test'
]
ACTION_LIST
=
[
'update'
,
'create'
,
'init'
,
'update-phab'
,
'update-security'
,
'readonly-on'
,
'readonly-off'
]
TYPE_LIST
=
[
'conf-lbs'
,
'conf-app'
,
'conf-phd'
,
'conf-dbs'
,
'conf-fs'
,
'conf-backup'
,
'conf-monit'
,
'conf-ci-slave'
,
'conf-shib'
,
'jenkins'
,
'common'
,
'files'
,
'repo'
]
#
# OPTIONS
#
parser
=
argparse
.
ArgumentParser
(
formatter_class
=
argparse
.
RawDescriptionHelpFormatter
,
description
=
'''Ansible deploy script for c4science
( ( )
( ) )\ ) ( )\ ) ( /( (
)\ ( /((()/( )\ (()/(( )\()) )\ (
(((_) )\())/(_)|((_) /(_))\ ((_)\ (((_) )\
)\___ ((_)\(_)) )\___(_))((_) _((_))\___((_)
((/ __| | (_) __((/ __|_ _| __| \| ((/ __| __|
| (__|_ _|\__ \| (__ | || _|| .` || (__| _|
\___| |_| |___/ \___|___|___|_|\_| \___|___|
'''
,
epilog
=
'''
Examples:
./deploy.py -h
./deploy.py create
./deploy.py update -t conf-app -e prod
./deploy.py update-phab -t conf-app conf-phd
./deploy.py update-security -t conf-fs
./deploy.py read-only-on
'''
)
parser
.
add_argument
(
'action'
,
choices
=
ACTION_LIST
)
parser
.
add_argument
(
'-t'
,
'--type'
,
choices
=
TYPE_LIST
,
nargs
=
'+'
)
parser
.
add_argument
(
'-e'
,
'--env'
,
choices
=
ENV_LIST
)
parser
.
add_argument
(
'-d'
,
'--dryrun'
,
action
=
'store_true'
)
parser
.
set_defaults
(
action
=
'update'
,
type
=
[],
env
=
'test'
)
argcomplete
.
autocomplete
(
parser
)
args
=
parser
.
parse_args
()
#
# ENVIRONMENT
#
if
args
.
env
==
'prod'
:
ANSIBLE_HOSTS
=
PROD_HOST
elif
args
.
env
==
'test'
:
ANSIBLE_HOSTS
=
TEST_HOST
#
# TYPE
#
ANSIBLE_TAGS
=
args
.
type
if
len
(
ANSIBLE_TAGS
)
>
0
:
ANSIBLE_SKIP
=
list
(
set
(
TYPE_LIST
)
-
set
(
ANSIBLE_TAGS
))
#
# ACTION
#
if
args
.
env
==
'prod'
:
ANSIBLE_BOOK
=
PROD_BOOK
elif
args
.
env
==
'test'
:
ANSIBLE_BOOK
=
TEST_BOOK
if
args
.
action
==
'update-phab'
:
if
args
.
env
==
'prod'
:
ANSIBLE_BOOK
=
'books/update_prod.yml'
elif
args
.
env
==
'test'
:
ANSIBLE_BOOK
=
'books/update_test.yml'
if
args
.
action
==
'update-security'
:
ANSIBLE_BOOK
=
'books/security-update.yml'
elif
args
.
action
==
'init'
:
pass
elif
args
.
action
==
'create'
:
if
args
.
env
==
'prod'
:
ANSIBLE_BOOK
=
'books/openstack_prod.yml'
elif
args
.
env
==
'test'
:
ANSIBLE_BOOK
=
'books/openstack_test.yml'
elif
args
.
action
==
'update'
:
if
'common'
not
in
ANSIBLE_TAGS
:
ANSIBLE_SKIP
.
extend
([
'common'
])
elif
args
.
action
==
'readonly-on'
:
if
args
.
env
==
'prod'
:
ANSIBLE_BOOK
=
'books/readonly-on.yml'
elif
args
.
action
==
'readonly-off'
:
if
args
.
env
==
'prod'
:
ANSIBLE_BOOK
=
'books/readonly-off.yml'
#
# MAIN
#
command
=
[
ANSIBLE
,
'--inventory-file'
,
ANSIBLE_HOSTS
]
if
args
.
dryrun
==
True
:
command
.
extend
([
'--check'
])
if
len
(
ANSIBLE_TAGS
)
>
0
:
command
.
extend
([
'--tags'
,
','
.
join
(
ANSIBLE_TAGS
)])
if
len
(
ANSIBLE_SKIP
)
>
0
:
command
.
extend
([
'--skip-tags'
,
','
.
join
(
ANSIBLE_SKIP
)])
command
.
extend
([
ANSIBLE_BOOK
])
print
' '
.
join
(
command
)
+
'
\n
'
subprocess
.
call
(
command
)
Event Timeline
Log In to Comment