Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
75381100
Commit
75381100
authored
Jul 31, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #736 from Ernest0x/db_create_extra_args
added extra arguments for database creation
parents
ce5f3dd1
24c1d321
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
6 deletions
+26
-6
library/mysql_db
+11
-3
library/postgresql_db
+15
-3
No files found.
library/mysql_db
View file @
75381100
...
...
@@ -39,8 +39,12 @@ def db_delete(cursor, db):
cursor
.
execute
(
query
)
return
True
def
db_create
(
cursor
,
db
):
query
=
"CREATE DATABASE
%
s"
%
db
def
db_create
(
cursor
,
db
,
encoding
,
collation
):
if
encoding
:
encoding
=
" CHARACTER SET
%
s"
%
encoding
if
collation
:
collation
=
" COLLATE
%
s"
%
collation
query
=
"CREATE DATABASE
%
s
%
s
%
s"
%
(
db
,
encoding
,
collation
)
res
=
cursor
.
execute
(
query
)
return
True
...
...
@@ -67,6 +71,8 @@ def main():
login_password
=
dict
(
default
=
None
),
login_host
=
dict
(
default
=
"localhost"
),
db
=
dict
(
required
=
True
),
encoding
=
dict
(
default
=
""
),
collation
=
dict
(
default
=
""
),
state
=
dict
(
default
=
"present"
,
choices
=
[
"absent"
,
"present"
]),
)
)
...
...
@@ -75,6 +81,8 @@ def main():
module
.
fail_json
(
msg
=
"the python mysqldb module is required"
)
db
=
module
.
params
[
"db"
]
encoding
=
module
.
params
[
"encoding"
]
collation
=
module
.
params
[
"collation"
]
state
=
module
.
params
[
"state"
]
# Either the caller passes both a username and password with which to connect to
...
...
@@ -105,7 +113,7 @@ def main():
changed
=
db_delete
(
cursor
,
db
)
else
:
if
state
==
"present"
:
changed
=
db_create
(
cursor
,
db
)
changed
=
db_create
(
cursor
,
db
,
encoding
,
collation
)
module
.
exit_json
(
changed
=
changed
,
db
=
db
)
...
...
library/postgresql_db
View file @
75381100
...
...
@@ -36,8 +36,14 @@ def db_delete(cursor, db):
cursor
.
execute
(
query
)
return
True
def
db_create
(
cursor
,
db
):
query
=
"CREATE DATABASE
%
s"
%
db
def
db_create
(
cursor
,
db
,
owner
,
template
,
encoding
):
if
owner
:
owner
=
" OWNER
%
s"
%
owner
if
template
:
template
=
" TEMPLATE
%
s"
%
template
if
encoding
:
encoding
=
" ENCODING '
%
s'"
%
encoding
query
=
"CREATE DATABASE
%
s
%
s
%
s
%
s"
%
(
db
,
owner
,
template
,
encoding
)
cursor
.
execute
(
query
)
return
True
...
...
@@ -52,6 +58,9 @@ def main():
login_password
=
dict
(
default
=
""
),
login_host
=
dict
(
default
=
""
),
db
=
dict
(
required
=
True
),
owner
=
dict
(
default
=
""
),
template
=
dict
(
default
=
""
),
encoding
=
dict
(
default
=
""
),
state
=
dict
(
default
=
"present"
,
choices
=
[
"absent"
,
"present"
]),
)
)
...
...
@@ -60,6 +69,9 @@ def main():
module
.
fail_json
(
msg
=
"the python psycopg2 module is required"
)
db
=
module
.
params
[
"db"
]
owner
=
module
.
params
[
"owner"
]
template
=
module
.
params
[
"template"
]
encoding
=
module
.
params
[
"encoding"
]
state
=
module
.
params
[
"state"
]
changed
=
False
try
:
...
...
@@ -79,7 +91,7 @@ def main():
changed
=
db_delete
(
cursor
,
db
)
else
:
if
state
==
"present"
:
changed
=
db_create
(
cursor
,
db
)
changed
=
db_create
(
cursor
,
db
,
owner
,
template
,
encoding
)
except
Exception
as
e
:
module
.
fail_json
(
msg
=
"Database query failed:
%
s"
%
e
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment