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
3807824c
Commit
3807824c
authored
Feb 23, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added file copy support w/ readme updates
parent
83d15afc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
21 deletions
+54
-21
README.md
+35
-13
bin/ansible
+4
-1
lib/ansible/__init__.py
+14
-7
library/copy
+1
-0
No files found.
README.md
View file @
3807824c
...
@@ -41,8 +41,15 @@ The default inventory file (-H) is ~/.ansible_hosts and is a list
...
@@ -41,8 +41,15 @@ The default inventory file (-H) is ~/.ansible_hosts and is a list
of all hostnames to target with ansible, one per line. These
of all hostnames to target with ansible, one per line. These
can be hostnames or IPs
can be hostnames or IPs
Example:
abc.example.com
def.example.com
192.168.10.50
192.168.10.51
This list is further filtered by the pattern wildcard (-P) to target
This list is further filtered by the pattern wildcard (-P) to target
specific hosts.
specific hosts.
This is covered below.
Comamnd line usage example
Comamnd line usage example
==========================
==========================
...
@@ -51,36 +58,51 @@ Run a module by name with arguments
...
@@ -51,36 +58,51 @@ Run a module by name with arguments
*
ssh-agent bash
*
ssh-agent bash
*
ssh-add ~/.ssh/id_rsa.pub
*
ssh-add ~/.ssh/id_rsa.pub
*
ansible -p "
*
.example.com" -
m
modName -a "arg1 arg2"
*
ansible -p "
*
.example.com" -
n
modName -a "arg1 arg2"
API Example
API Example
===========
===========
The API is simple and returns basic datastructures.
The API is simple and returns basic datastructures.
import ansible
import ansible
runner = ansible.Runner(command='inventory', host_list=
[
'xyz.example.com', '...'
]
)
runner = ansible.Runner(command='inventory', host_list=['xyz.example.com', '...'])
data = runner.run()
data = runner.run()
{
{
'xyz.example.com' :
[
'any kind of datastructure is returnable'
]
,
'xyz.example.com' : [ 'any kind of datastructure is returnable' ],
'foo.example.com' : None, # failed to connect,
'foo.example.com' : None, # failed to connect,
...
...
}
}
Additional options to runner include the number of forks, hostname
Additional options to runner include the number of forks, hostname
exclusion pattern, library path, and so on. Read the source, it's not
exclusion pattern, library path, and so on. Read the source, it's not
complicated.
complicated.
Patterns
========
To target only hosts starting with "rtp", for example:
*
ansible "rtp
*
" -n command -a "yum update apache"
Parallelism
Parallelism
===========
===========
Specify the number of forks to use, to run things in greater parallelism.
Specify the number of forks to use, to run things in greater parallelism.
* ansible -f 10 "*.example.com" -
m modName -a "arg1 arg2
"
* ansible -f 10 "*.example.com" -
n command -a "yum update apache
"
10 forks. The default is 3. 5 is right out.
10 forks. The default is 3. 5 is right out.
File Transfer
=============
Yeah, it does that too.
*
ansible -n copy -a "/etc/hosts /tmp/hosts"
Bundled Modules
Bundled Modules
===============
===============
...
@@ -119,8 +141,8 @@ Future plans
...
@@ -119,8 +141,8 @@ Future plans
Author
Author
======
======
Michael DeHaan
<michael.dehaan@gmail.com>
Michael DeHaan
<michael.dehaan@gmail.com>
http://michaeldehaan.net/
http://michaeldehaan.net/
bin/ansible
View file @
3807824c
...
@@ -35,10 +35,13 @@ class Cli(object):
...
@@ -35,10 +35,13 @@ class Cli(object):
options
,
args
=
parser
.
parse_args
()
options
,
args
=
parser
.
parse_args
()
host_list
=
self
.
_host_list
(
options
.
host_list
)
host_list
=
self
.
_host_list
(
options
.
host_list
)
# TODO: more shell like splitting on module_args would
# be a good idea
return
ansible
.
Runner
(
return
ansible
.
Runner
(
module_name
=
options
.
module_name
,
module_name
=
options
.
module_name
,
module_path
=
options
.
module_path
,
module_path
=
options
.
module_path
,
module_args
=
options
.
module_args
,
module_args
=
options
.
module_args
.
split
(
' '
)
,
host_list
=
host_list
,
host_list
=
host_list
,
forks
=
options
.
forks
,
forks
=
options
.
forks
,
pattern
=
options
.
pattern
,
pattern
=
options
.
pattern
,
...
...
lib/ansible/__init__.py
View file @
3807824c
...
@@ -39,7 +39,7 @@ class Pooler(object):
...
@@ -39,7 +39,7 @@ class Pooler(object):
class
Runner
(
object
):
class
Runner
(
object
):
def
__init__
(
self
,
host_list
=
[],
module_path
=
None
,
def
__init__
(
self
,
host_list
=
[],
module_path
=
None
,
module_name
=
None
,
module_args
=
''
,
module_name
=
None
,
module_args
=
[]
,
forks
=
3
,
timeout
=
60
,
pattern
=
'*'
):
forks
=
3
,
timeout
=
60
,
pattern
=
'*'
):
self
.
host_list
=
host_list
self
.
host_list
=
host_list
...
@@ -73,15 +73,22 @@ class Runner(object):
...
@@ -73,15 +73,22 @@ class Runner(object):
conn
=
self
.
_connect
(
host
)
conn
=
self
.
_connect
(
host
)
if
not
conn
:
if
not
conn
:
return
[
host
,
None
]
return
[
host
,
None
]
outpath
=
self
.
_copy_module
(
conn
)
if
self
.
module_name
!=
"copy"
:
self
.
_exec_command
(
conn
,
"chmod +x
%
s"
%
outpath
)
outpath
=
self
.
_copy_module
(
conn
)
cmd
=
self
.
_command
(
outpath
)
self
.
_exec_command
(
conn
,
"chmod +x
%
s"
%
outpath
)
result
=
self
.
_exec_command
(
conn
,
cmd
)
cmd
=
self
.
_command
(
outpath
)
result
=
json
.
loads
(
result
)
result
=
self
.
_exec_command
(
conn
,
cmd
)
result
=
json
.
loads
(
result
)
else
:
ftp
=
conn
.
open_sftp
()
ftp
.
put
(
self
.
module_args
[
0
],
self
.
module_args
[
1
])
ftp
.
close
()
return
[
host
,
1
]
return
[
host
,
result
]
return
[
host
,
result
]
def
_command
(
self
,
outpath
):
def
_command
(
self
,
outpath
):
cmd
=
"
%
s
%
s"
%
(
outpath
,
self
.
module_args
)
cmd
=
"
%
s
%
s"
%
(
outpath
,
" "
.
join
(
self
.
module_args
)
)
return
cmd
return
cmd
def
_exec_command
(
self
,
conn
,
cmd
):
def
_exec_command
(
self
,
conn
,
cmd
):
...
...
library/copy
0 → 100644
View file @
3807824c
# copy is built-in to ansible's core, so the module here is just a placeholder
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