Update IOS, IOSXR, JUNOS, & OpenSwitch for environment vars.

This commit is contained in:
Nathaniel Case 2016-04-01 10:53:44 -04:00
commit 7290b6282d
8 changed files with 88 additions and 40 deletions

View file

@ -19,8 +19,8 @@
import re import re
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule, env_fallback
from ansible.module_utils.shell import Shell, Command, HAS_PARAMIKO from ansible.module_utils.shell import Shell, ShellError, Command, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse from ansible.module_utils.netcfg import parse
NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I) NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
@ -28,10 +28,11 @@ NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
NET_COMMON_ARGS = dict( NET_COMMON_ARGS = dict(
host=dict(required=True), host=dict(required=True),
port=dict(default=22, type='int'), port=dict(default=22, type='int'),
username=dict(required=True), username=dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
password=dict(no_log=True), password=dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD'])),
authorize=dict(default=False, type='bool'), ssh_keyfile=dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
auth_pass=dict(no_log=True), authorize=dict(default=False, fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
auth_pass=dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])),
provider=dict() provider=dict()
) )
@ -72,12 +73,12 @@ class Cli(object):
username = self.module.params['username'] username = self.module.params['username']
password = self.module.params['password'] password = self.module.params['password']
key_filename = self.module.params['ssh_keyfile']
try: try:
self.shell = Shell(kickstart=False, prompts_re=CLI_PROMPTS_RE, self.shell = Shell(kickstart=False, prompts_re=CLI_PROMPTS_RE,
errors_re=CLI_ERRORS_RE) errors_re=CLI_ERRORS_RE)
self.shell.open(host, port=port, username=username, self.shell.open(host, port=port, username=username, password=password, key_filename=key_filename)
password=password)
except Exception, exc: except Exception, exc:
msg = 'failed to connect to %s:%s - %s' % (host, port, str(exc)) msg = 'failed to connect to %s:%s - %s' % (host, port, str(exc))
self.module.fail_json(msg=msg) self.module.fail_json(msg=msg)

View file

@ -19,7 +19,7 @@
import re import re
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule, env_fallback
from ansible.module_utils.shell import Shell, HAS_PARAMIKO from ansible.module_utils.shell import Shell, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse from ansible.module_utils.netcfg import parse
@ -28,8 +28,9 @@ NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
NET_COMMON_ARGS = dict( NET_COMMON_ARGS = dict(
host=dict(required=True), host=dict(required=True),
port=dict(default=22, type='int'), port=dict(default=22, type='int'),
username=dict(required=True), username=dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
password=dict(no_log=True), password=dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD'])),
ssh_keyfile=dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
provider=dict() provider=dict()
) )
@ -68,11 +69,11 @@ class Cli(object):
username = self.module.params['username'] username = self.module.params['username']
password = self.module.params['password'] password = self.module.params['password']
key_filename = self.module.params['ssh_keyfile']
try: try:
self.shell = Shell(kickstart=False, prompts_re=CLI_PROMPTS_RE, self.shell = Shell(kickstart=False, prompts_re=CLI_PROMPTS_RE, errors_re=CLI_ERRORS_RE)
errors_re=CLI_ERRORS_RE) self.shell.open(host, port=port, username=username, password=password, key_filename=key_filename)
self.shell.open(host, port=port, username=username, password=password)
except Exception, exc: except Exception, exc:
msg = 'failed to connecto to %s:%s - %s' % (host, port, str(exc)) msg = 'failed to connecto to %s:%s - %s' % (host, port, str(exc))
self.module.fail_json(msg=msg) self.module.fail_json(msg=msg)

View file

@ -17,15 +17,16 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# #
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule, env_fallback
from ansible.module_utils.shell import Shell, HAS_PARAMIKO from ansible.module_utils.shell import Shell, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse from ansible.module_utils.netcfg import parse
NET_COMMON_ARGS = dict( NET_COMMON_ARGS = dict(
host=dict(required=True), host=dict(required=True),
port=dict(default=22, type='int'), port=dict(default=22, type='int'),
username=dict(required=True), username=dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
password=dict(no_log=True), password=dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD'])),
ssh_keyfile=dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
provider=dict() provider=dict()
) )
@ -49,11 +50,12 @@ class Cli(object):
username = self.module.params['username'] username = self.module.params['username']
password = self.module.params['password'] password = self.module.params['password']
key_filename = self.module.params['ssh_keyfile']
self.shell = Shell() self.shell = Shell()
try: try:
self.shell.open(host, port=port, username=username, password=password) self.shell.open(host, port=port, username=username, password=password, key_filename=key_filename)
except Exception, exc: except Exception, exc:
msg = 'failed to connecto to %s:%s - %s' % (host, port, str(exc)) msg = 'failed to connecto to %s:%s - %s' % (host, port, str(exc))
self.module.fail_json(msg=msg) self.module.fail_json(msg=msg)

View file

@ -29,7 +29,7 @@ try:
except ImportError: except ImportError:
HAS_OPS = False HAS_OPS = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule, env_fallback
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
from ansible.module_utils.shell import Shell, HAS_PARAMIKO from ansible.module_utils.shell import Shell, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse from ansible.module_utils.netcfg import parse
@ -39,8 +39,9 @@ NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
NET_COMMON_ARGS = dict( NET_COMMON_ARGS = dict(
host=dict(), host=dict(),
port=dict(type='int'), port=dict(type='int'),
username=dict(), username=dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
password=dict(no_log=True), password=dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD'])),
ssh_keyfile=dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
use_ssl=dict(default=True, type='bool'), use_ssl=dict(default=True, type='bool'),
transport=dict(default='ssh', choices=['ssh', 'cli', 'rest']), transport=dict(default='ssh', choices=['ssh', 'cli', 'rest']),
provider=dict() provider=dict()
@ -154,9 +155,10 @@ class Cli(object):
username = self.module.params['username'] username = self.module.params['username']
password = self.module.params['password'] password = self.module.params['password']
key_filename = self.module.params['ssh_keyfile']
self.shell = Shell() self.shell = Shell()
self.shell.open(host, port=port, username=username, password=password) self.shell.open(host, port=port, username=username, password=password, key_filename=key_filename)
def send(self, commands, encoding='text'): def send(self, commands, encoding='text'):
return self.shell.send(commands) return self.shell.send(commands)

View file

@ -39,20 +39,32 @@ options:
description: description:
- Configures the usename to use to authenticate the connection to - Configures the usename to use to authenticate the connection to
the remote device. The value of I(username) is used to authenticate the remote device. The value of I(username) is used to authenticate
the SSH session the SSH session. If the value is not specified in the task, the
required: true value of environment variable ANSIBLE_NET_USERNAME will be used instead.
required: false
password: password:
description: description:
- Specifies the password to use when authentication the connection to - Specifies the password to use to authenticate the connection to
the remote device. The value of I(password) is used to authenticate the remote device. The value of I(password) is used to authenticate
the SSH session the SSH session. If the value is not specified in the task, the
value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
required: false required: false
default: null default: null
ssh_keyfile:
description:
- Specifies the SSH key to use to authenticate the connection to
the remote device. The value of I(ssh_keyfile) is the path to the
key used to authenticate the SSH session. If the value is not specified
in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE
will be used instead.
required: false
authorize: authorize:
description: description:
- Instructs the module to enter priviledged mode on the remote device - Instructs the module to enter priviledged mode on the remote device
before sending any commands. If not specified, the device will before sending any commands. If not specified, the device will
attempt to excecute all commands in non-priviledged mode. attempt to excecute all commands in non-priviledged mode. If the value
is not specified in the task, the value of environment variable
ANSIBLE_NET_AUTHORIZE will be used instead.
required: false required: false
default: no default: no
choices: ['yes', 'no'] choices: ['yes', 'no']
@ -60,7 +72,8 @@ options:
description: description:
- Specifies the password to use if required to enter privileged mode - Specifies the password to use if required to enter privileged mode
on the remote device. If I(authorize) is false, then this argument on the remote device. If I(authorize) is false, then this argument
does nothing does nothing. If the value is not specified in the task, the value of
environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
required: false required: false
default: none default: none
provider: provider:

View file

@ -39,15 +39,25 @@ options:
description: description:
- Configures the usename to use to authenticate the connection to - Configures the usename to use to authenticate the connection to
the remote device. The value of I(username) is used to authenticate the remote device. The value of I(username) is used to authenticate
the SSH session the SSH session. If the value is not specified in the task, the
required: true value of environment variable ANSIBLE_NET_USERNAME will be used instead.
required: false
password: password:
description: description:
- Specifies the password to use when authentication the connection to - Specifies the password to use to authenticate the connection to
the remote device. The value of I(password) is used to authenticate the remote device. The value of I(password) is used to authenticate
the SSH session the SSH session. If the value is not specified in the task, the
value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
required: false required: false
default: null default: null
ssh_keyfile:
description:
- Specifies the SSH key to use to authenticate the connection to
the remote device. The value of I(ssh_keyfile) is the path to the
key used to authenticate the SSH session. If the value is not specified
in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE
will be used instead.
required: false
provider: provider:
description: description:
- Convience method that allows all M(iosxr) arguments to be passed as - Convience method that allows all M(iosxr) arguments to be passed as

View file

@ -39,15 +39,25 @@ options:
description: description:
- Configures the usename to use to authenticate the connection to - Configures the usename to use to authenticate the connection to
the remote device. The value of I(username) is used to authenticate the remote device. The value of I(username) is used to authenticate
the SSH session the SSH session. If the value is not specified in the task, the
required: true value of environment variable ANSIBLE_NET_USERNAME will be used instead.
required: false
password: password:
description: description:
- Specifies the password to use when authentication the connection to - Specifies the password to use to authenticate the connection to
the remote device. The value of I(password) is used to authenticate the remote device. The value of I(password) is used to authenticate
the SSH session the SSH session. If the value is not specified in the task, the
value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
required: false required: false
default: null default: null
ssh_keyfile:
description:
- Specifies the SSH key to use to authenticate the connection to
the remote device. The value of I(ssh_keyfile) is the path to the key
used to authenticate the SSH session. If the value is not specified in
the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE
will be used instead.
required: false
provider: provider:
description: description:
- Convience method that allows all M(ios) arguments to be passed as - Convience method that allows all M(ios) arguments to be passed as

View file

@ -44,16 +44,25 @@ options:
the remote device. The value of I(username) is used to authenticate the remote device. The value of I(username) is used to authenticate
either the CLI login or the eAPI authentication depending on which either the CLI login or the eAPI authentication depending on which
transport is used. Note this argument does not affect the SSH transport is used. Note this argument does not affect the SSH
transport. transport. If the value is not specified in the task, the value of
required: true environment variable ANSIBLE_NET_USERNAME will be used instead.
required: false
password: password:
description: description:
- Specifies the password to use when authentication the connection to - Specifies the password to use to authenticate the connection to
the remote device. This is a common argument used for either I(cli) the remote device. This is a common argument used for either I(cli)
or I(rest) transports. Note this argument does not affect the SSH or I(rest) transports. Note this argument does not affect the SSH
transport transport. If the value is not specified in the task, the value of
environment variable ANSIBLE_NET_PASSWORD will be used instead.
required: false required: false
default: null default: null
ssh_keyfile:
description:
- Specifies the SSH key to use to authenticate the connection to
the remote device. This argument is only used for the I(cli)
transports. If the value is not specified in the task, the value of
environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
required: false
transport: transport:
description: description:
- Configures the transport connection to use when connecting to the - Configures the transport connection to use when connecting to the