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
961bee00
Commit
961bee00
authored
Aug 18, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
centralized the definition of 'localhost'
parent
29724f35
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
13 deletions
+13
-13
lib/ansible/constants.py
+1
-0
lib/ansible/inventory/__init__.py
+6
-7
lib/ansible/plugins/action/synchronize.py
+6
-6
No files found.
lib/ansible/constants.py
View file @
961bee00
...
...
@@ -245,3 +245,4 @@ VAULT_VERSION_MIN = 1.0
VAULT_VERSION_MAX
=
1.0
MAX_FILE_SIZE_FOR_DIFF
=
1
*
1024
*
1024
TREE_DIR
=
None
LOCALHOST
=
frozenset
([
'127.0.0.1'
,
'localhost'
,
'::1'
])
lib/ansible/inventory/__init__.py
View file @
961bee00
...
...
@@ -49,7 +49,6 @@ class Inventory(object):
# 'parser', '_vars_per_host', '_vars_per_group', '_hosts_cache', '_groups_list',
# '_pattern_cache', '_vault_password', '_vars_plugins', '_playbook_basedir']
LOCALHOST_ALIASES
=
frozenset
((
'localhost'
,
'127.0.0.1'
,
'::1'
))
def
__init__
(
self
,
loader
,
variable_manager
,
host_list
=
C
.
DEFAULT_HOST_LIST
):
# the host file file, or script path, or list of hosts
...
...
@@ -370,7 +369,7 @@ class Inventory(object):
for
host
in
matching_hosts
:
__append_host_to_results
(
host
)
if
pattern
in
self
.
LOCALHOST_ALIASES
and
len
(
results
)
==
0
:
if
pattern
in
C
.
LOCALHOST
and
len
(
results
)
==
0
:
new_host
=
self
.
_create_implicit_localhost
(
pattern
)
results
.
append
(
new_host
)
return
results
...
...
@@ -404,15 +403,15 @@ class Inventory(object):
def
get_host
(
self
,
hostname
):
if
hostname
not
in
self
.
_hosts_cache
:
self
.
_hosts_cache
[
hostname
]
=
self
.
_get_host
(
hostname
)
if
hostname
in
self
.
LOCALHOST_ALIASES
:
for
host
in
self
.
LOCALHOST_ALIASES
.
difference
((
hostname
,)):
if
hostname
in
C
.
LOCALHOST
:
for
host
in
C
.
LOCALHOST
.
difference
((
hostname
,)):
self
.
_hosts_cache
[
host
]
=
self
.
_hosts_cache
[
hostname
]
return
self
.
_hosts_cache
[
hostname
]
def
_get_host
(
self
,
hostname
):
if
hostname
in
self
.
LOCALHOST_ALIASES
:
if
hostname
in
C
.
LOCALHOST
:
for
host
in
self
.
get_group
(
'all'
)
.
get_hosts
():
if
host
.
name
in
self
.
LOCALHOST_ALIASES
:
if
host
.
name
in
C
.
LOCALHOST
:
return
host
return
self
.
_create_implicit_localhost
(
hostname
)
matching_host
=
None
...
...
@@ -511,7 +510,7 @@ class Inventory(object):
""" return a list of hostnames for a pattern """
result
=
[
h
for
h
in
self
.
get_hosts
(
pattern
)
]
if
len
(
result
)
==
0
and
pattern
in
self
.
LOCALHOST_ALIASES
:
if
len
(
result
)
==
0
and
pattern
in
C
.
LOCALHOST
:
result
=
[
pattern
]
return
result
...
...
lib/ansible/plugins/action/synchronize.py
View file @
961bee00
...
...
@@ -23,7 +23,7 @@ import os.path
from
ansible.plugins.action
import
ActionBase
from
ansible.plugins
import
connection_loader
from
ansible.utils.boolean
import
boolean
from
ansible
import
constants
from
ansible
import
constants
as
C
class
ActionModule
(
ActionBase
):
...
...
@@ -46,7 +46,7 @@ class ActionModule(ActionBase):
def
_process_origin
(
self
,
host
,
path
,
user
):
if
host
not
in
(
'127.0.0.1'
,
'localhost'
,
'::1'
)
:
if
host
not
in
C
.
LOCALHOST
:
if
user
:
return
'
%
s@
%
s:
%
s'
%
(
user
,
host
,
path
)
else
:
...
...
@@ -58,7 +58,7 @@ class ActionModule(ActionBase):
def
_process_remote
(
self
,
host
,
path
,
user
):
transport
=
self
.
_play_context
.
connection
if
host
not
in
(
'127.0.0.1'
,
'localhost'
,
'::1'
)
or
transport
!=
"local"
:
if
host
not
in
C
.
LOCALHOST
or
transport
!=
"local"
:
if
user
:
return
'
%
s@
%
s:
%
s'
%
(
user
,
host
,
path
)
else
:
...
...
@@ -115,11 +115,11 @@ class ActionModule(ActionBase):
src_host
=
'127.0.0.1'
dest_host
=
task_vars
.
get
(
'ansible_ssh_host'
)
or
task_vars
.
get
(
'inventory_hostname'
)
dest_is_local
=
dest_host
in
(
'127.0.0.1'
,
'localhost'
,
'::1'
)
dest_is_local
=
dest_host
in
C
.
LOCALHOST
# CHECK FOR NON-DEFAULT SSH PORT
if
self
.
_task
.
args
.
get
(
'dest_port'
,
None
)
is
None
:
inv_port
=
task_vars
.
get
(
'ansible_ssh_port'
,
None
)
or
constants
.
DEFAULT_REMOTE_PORT
inv_port
=
task_vars
.
get
(
'ansible_ssh_port'
,
None
)
or
C
.
DEFAULT_REMOTE_PORT
if
inv_port
is
not
None
:
self
.
_task
.
args
[
'dest_port'
]
=
inv_port
...
...
@@ -218,7 +218,7 @@ class ActionModule(ActionBase):
self
.
_task
.
args
[
'rsync_path'
]
=
'"
%
s"'
%
rsync_path
if
use_ssh_args
:
self
.
_task
.
args
[
'ssh_args'
]
=
constants
.
ANSIBLE_SSH_ARGS
self
.
_task
.
args
[
'ssh_args'
]
=
C
.
ANSIBLE_SSH_ARGS
# run the module and store the result
result
=
self
.
_execute_module
(
'synchronize'
,
task_vars
=
task_vars
)
...
...
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