Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify the mysql port #4011

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Misc changes:
* added IAM role support to EC2 module
* fixes for OpenBSD package module to avoid shell expansion
* git module upgrades to allow --depth and --version to be used together
* new lookup plugin, "with_flat_list"
* new lookup plugin, "with_flattened"
* extra vars (-e) variables can be used in playbook include paths
* improved reporting for invalid sudo passwords
* improved reporting for inability to find a suitable tmp location
Expand Down
3 changes: 1 addition & 2 deletions lib/ansible/playbook/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,13 @@ def _build_role_dependencies(self, roles, dep_stack, passed_vars={}, level=0):
if data:
dependencies = data.get('dependencies',[])
for dep in dependencies:
allow_dupes = False
(dep_path,dep_vars) = self._get_role_path(dep)
meta = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'meta')))
if os.path.isfile(meta):
meta_data = utils.parse_yaml_from_file(meta)
if meta_data:
allow_dupes = utils.boolean(meta_data.get('allow_duplicates',''))
else:
allow_dupes = False

if not allow_dupes:
if dep in self.included_roles:
Expand Down
21 changes: 13 additions & 8 deletions lib/ansible/runner/connection_plugins/accelerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, runner, host, port, user, password, private_key_file, *args,
self.user = user
self.key = utils.key_for_hostname(host)
self.port = port[0]
self.fbport = port[1]
self.accport = port[1]
self.is_connected = False

self.ssh = SSHConnection(
Expand All @@ -58,15 +58,20 @@ def __init__(self, runner, host, port, user, password, private_key_file, *args,
private_key_file=private_key_file
)

if not self.accport:
self.accport = constants.ACCELERATE_PORT

# attempt to work around shared-memory funness
if getattr(self.runner, 'aes_keys', None):
utils.AES_KEYS = self.runner.aes_keys

def _execute_fb_module(self):
args = "password=%s port=%s" % (base64.b64encode(self.key.__str__()), str(self.fbport))
def _execute_accelerate_module(self):
args = "password=%s port=%s" % (base64.b64encode(self.key.__str__()), str(self.accport))
inject = dict(password=self.key)
inject = utils.combine_vars(inject, self.runner.inventory.get_variables(self.host))
self.ssh.connect()
tmp_path = self.runner._make_tmp_path(self.ssh)
return self.runner._execute_module(self.ssh, tmp_path, 'accelerate', args, inject={"password":self.key})
return self.runner._execute_module(self.ssh, tmp_path, 'accelerate', args, inject=inject)

def connect(self, allow_ssh=True):
''' activates the connection object '''
Expand All @@ -76,10 +81,10 @@ def connect(self, allow_ssh=True):
# TODO: make the timeout and retries configurable?
tries = 3
self.conn = socket.socket()
self.conn.settimeout(30.0)
self.conn.settimeout(300.0)
while tries > 0:
try:
self.conn.connect((self.host,self.fbport))
self.conn.connect((self.host,self.accport))
break
except:
time.sleep(0.1)
Expand All @@ -90,12 +95,12 @@ def connect(self, allow_ssh=True):
except:
if allow_ssh:
vvv("Falling back to ssh to startup accelerated mode")
res = self._execute_fb_module()
res = self._execute_accelerate_module()
if not res.is_successful():
raise errors.AnsibleError("Failed to launch the accelerated daemon on %s (reason: %s)" % (self.host,res.result.get('msg')))
return self.connect(allow_ssh=False)
else:
raise errors.AnsibleError("Failed to connect to %s:%s" % (self.host,self.fbport))
raise errors.AnsibleError("Failed to connect to %s:%s" % (self.host,self.accport))
self.is_connected = True
return self

Expand Down
12 changes: 8 additions & 4 deletions lib/ansible/utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
_basedirs = []

def push_basedir(basedir):
# avoid pushing the same absolute dir more than once
basedir = os.path.abspath(basedir)
if basedir not in _basedirs:
_basedirs.insert(0, basedir)

Expand Down Expand Up @@ -97,7 +99,7 @@ def _get_paths(self):
ret = []
ret += self._extra_dirs
for basedir in _basedirs:
fullpath = os.path.join(basedir, self.subdir)
fullpath = os.path.abspath(os.path.join(basedir, self.subdir))
if os.path.isdir(fullpath):
files = glob.glob("%s/*" % fullpath)
for file in files:
Expand All @@ -109,12 +111,13 @@ def _get_paths(self):
# look in any configured plugin paths, allow one level deep for subcategories
configured_paths = self.config.split(os.pathsep)
for path in configured_paths:
path = os.path.expanduser(path)
path = os.path.abspath(os.path.expanduser(path))
contents = glob.glob("%s/*" % path)
for c in contents:
if os.path.isdir(c):
if os.path.isdir(c) and c not in ret:
ret.append(c)
ret.append(path)
if path not in ret:
ret.append(path)

# look for any plugins installed in the package subtree
ret.extend(self._get_package_paths())
Expand All @@ -128,6 +131,7 @@ def add_directory(self, directory, with_subdir=False):
''' Adds an additional directory to the search path '''

self._paths = None
directory = os.path.abspath(directory)

if directory is not None:
if with_subdir:
Expand Down
8 changes: 7 additions & 1 deletion library/database/mysql_db
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ options:
- Host running the database
required: false
default: localhost
login_port:
description:
- Port of the MySQL server
required: false
default: 3306
login_unix_socket:
description:
- The path to a Unix domain socket for local connections
Expand Down Expand Up @@ -197,6 +202,7 @@ def main():
login_user=dict(default=None),
login_password=dict(default=None),
login_host=dict(default="localhost"),
login_port=dict(default="3306"),
login_unix_socket=dict(default=None),
db=dict(required=True, aliases=['name']),
encoding=dict(default=""),
Expand Down Expand Up @@ -242,7 +248,7 @@ def main():
if module.params["login_unix_socket"]:
db_connection = MySQLdb.connect(host=module.params["login_host"], unix_socket=module.params["login_unix_socket"], user=login_user, passwd=login_password, db=connect_to_db)
else:
db_connection = MySQLdb.connect(host=module.params["login_host"], user=login_user, passwd=login_password, db=connect_to_db)
db_connection = MySQLdb.connect(host=module.params["login_host"], port=int(module.params["login_port"]), user=login_user, passwd=login_password, db=connect_to_db)
cursor = db_connection.cursor()
except Exception, e:
module.fail_json(msg="unable to connect, check login_user and login_password are correct, or alternatively check ~/.my.cnf contains credentials")
Expand Down
8 changes: 7 additions & 1 deletion library/database/mysql_user
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ options:
- Host running the database
required: false
default: localhost
login_port:
description:
- Port of the MySQL server
required: false
default: 3306
login_unix_socket:
description:
- The path to a Unix domain socket for local connections
Expand Down Expand Up @@ -326,7 +331,7 @@ def connect(module, login_user, login_password):
if module.params["login_unix_socket"]:
db_connection = MySQLdb.connect(host=module.params["login_host"], unix_socket=module.params["login_unix_socket"], user=login_user, passwd=login_password, db="mysql")
else:
db_connection = MySQLdb.connect(host=module.params["login_host"], user=login_user, passwd=login_password, db="mysql")
db_connection = MySQLdb.connect(host=module.params["login_host"], port=int(module.params["login_port"]), user=login_user, passwd=login_password, db="mysql")
return db_connection.cursor()

# ===========================================
Expand All @@ -339,6 +344,7 @@ def main():
login_user=dict(default=None),
login_password=dict(default=None),
login_host=dict(default="localhost"),
login_port=dict(default="3306"),
login_unix_socket=dict(default=None),
user=dict(required=True, aliases=['name']),
password=dict(default=None),
Expand Down