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
53207ddb
Commit
53207ddb
authored
Jul 01, 2013
by
Stavros Korokithakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add --only-if-changed option.
parent
6d5ac43d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
bin/ansible-pull
+14
-5
No files found.
bin/ansible-pull
View file @
53207ddb
...
@@ -45,8 +45,9 @@ import socket
...
@@ -45,8 +45,9 @@ import socket
from
optparse
import
OptionParser
from
optparse
import
OptionParser
DEFAULT_PLAYBOOK
=
'local.yml'
DEFAULT_PLAYBOOK
=
'local.yml'
PLAYBOOK_ERRORS
=
{
1
:
'File does not exist'
,
PLAYBOOK_ERRORS
=
{
1
:
'File does not exist'
,
2
:
'File is not readable'
}
2
:
'File is not readable'
}
def
_run
(
cmd
):
def
_run
(
cmd
):
print
>>
sys
.
stderr
,
"Running: '
%
s'"
%
cmd
print
>>
sys
.
stderr
,
"Running: '
%
s'"
%
cmd
...
@@ -56,7 +57,8 @@ def _run(cmd):
...
@@ -56,7 +57,8 @@ def _run(cmd):
print
out
print
out
if
cmd
.
returncode
!=
0
:
if
cmd
.
returncode
!=
0
:
print
>>
sys
.
stderr
,
err
print
>>
sys
.
stderr
,
err
return
cmd
.
returncode
return
cmd
.
returncode
,
out
def
try_playbook
(
path
):
def
try_playbook
(
path
):
if
not
os
.
path
.
exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
...
@@ -65,6 +67,7 @@ def try_playbook(path):
...
@@ -65,6 +67,7 @@ def try_playbook(path):
return
2
return
2
return
0
return
0
def
select_playbook
(
path
,
args
):
def
select_playbook
(
path
,
args
):
playbook
=
None
playbook
=
None
if
len
(
args
)
>
0
and
args
[
0
]
is
not
None
:
if
len
(
args
)
>
0
and
args
[
0
]
is
not
None
:
...
@@ -89,12 +92,15 @@ def select_playbook(path, args):
...
@@ -89,12 +92,15 @@ def select_playbook(path, args):
print
>>
sys
.
stderr
,
"
\n
"
.
join
(
errors
)
print
>>
sys
.
stderr
,
"
\n
"
.
join
(
errors
)
return
playbook
return
playbook
def
main
(
args
):
def
main
(
args
):
""" Set up and run a local playbook """
""" Set up and run a local playbook """
usage
=
"
%
prog [options] [playbook.yml]"
usage
=
"
%
prog [options] [playbook.yml]"
parser
=
OptionParser
(
usage
=
usage
)
parser
=
OptionParser
(
usage
=
usage
)
parser
.
add_option
(
'--purge'
,
default
=
False
,
action
=
'store_true'
,
parser
.
add_option
(
'--purge'
,
default
=
False
,
action
=
'store_true'
,
help
=
'Purge git checkout after playbook run'
)
help
=
'Purge git checkout after playbook run'
)
parser
.
add_option
(
'-o'
,
'--only-if-changed'
,
dest
=
'ifchanged'
,
default
=
False
,
action
=
'store_true'
,
help
=
'Only run the playbook if the repository has been updated'
)
parser
.
add_option
(
'-d'
,
'--directory'
,
dest
=
'dest'
,
default
=
None
,
parser
.
add_option
(
'-d'
,
'--directory'
,
dest
=
'dest'
,
default
=
None
,
help
=
'Directory to clone git repository to'
)
help
=
'Directory to clone git repository to'
)
parser
.
add_option
(
'-U'
,
'--url'
,
dest
=
'url'
,
default
=
None
,
parser
.
add_option
(
'-U'
,
'--url'
,
dest
=
'url'
,
default
=
None
,
...
@@ -123,9 +129,12 @@ def main(args):
...
@@ -123,9 +129,12 @@ def main(args):
cmd
=
'ansible all -c local -i "
%
s" --limit "
%
s" -m git -a "
%
s"'
%
(
cmd
=
'ansible all -c local -i "
%
s" --limit "
%
s" -m git -a "
%
s"'
%
(
inv_opts
,
limit_opts
,
git_opts
inv_opts
,
limit_opts
,
git_opts
)
)
rc
=
_run
(
cmd
)
rc
,
out
=
_run
(
cmd
)
if
rc
!=
0
:
if
rc
!=
0
:
return
rc
return
rc
elif
options
.
ifchanged
and
'"changed": true'
not
in
out
:
print
"Repository has not changed, quitting."
return
0
playbook
=
select_playbook
(
options
.
dest
,
args
)
playbook
=
select_playbook
(
options
.
dest
,
args
)
...
@@ -137,7 +146,7 @@ def main(args):
...
@@ -137,7 +146,7 @@ def main(args):
if
options
.
inventory
:
if
options
.
inventory
:
cmd
+=
' -i "
%
s"'
%
options
.
inventory
cmd
+=
' -i "
%
s"'
%
options
.
inventory
os
.
chdir
(
options
.
dest
)
os
.
chdir
(
options
.
dest
)
rc
=
_run
(
cmd
)
rc
,
out
=
_run
(
cmd
)
if
options
.
purge
:
if
options
.
purge
:
os
.
chdir
(
'/'
)
os
.
chdir
(
'/'
)
...
...
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