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 backup filename and dir path option for config network modules #50801

Merged
merged 4 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
41 changes: 38 additions & 3 deletions lib/ansible/modules/network/aireos/aireos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
description:
- This argument will cause the module to create a full backup of
the current C(running-config) from the remote device before any
changes are made. The backup file is written to the C(backup)
folder in the playbook root directory. If the directory does not
exist, it is created.
changes are made. If the C(backup_options) value is not given,
the backup file is written to the C(backup) folder in the playbook
root directory. If the directory does not exist, it is created.
type: bool
default: 'no'
running_config:
Expand Down Expand Up @@ -131,6 +131,28 @@
of the current device's configuration against. When specifying this
argument, the task should also modify the C(diff_against) value and
set it to I(intended).
backup_options:
description:
- This is a dict object containing configurable options related to backup file path.
The value of this option is read only when C(backup) is set to I(yes), if C(backup) is set
to I(no) this option will be silently ignored.
suboptions:
filename:
description:
- The filename to be used to store the backup configuration. If the the filename
is not given it will be generated based on the hostname, current time and date
in format defined by <hostname>_config.<current-date>@<current-time>
dir_path:
description:
- This option provides the path ending with directory name in which the backup
configuration file will be stored. If the directory does not exist it will be first
created and the filename is either the value of C(filename) or default filename
as described in C(filename) options description. If the path value is not given
in that case a I(backup) directory will be created in the current working directory
and backup configuration will be copied in C(filename) within I(backup) directory.
type: path
type: dict
version_added: "2.8"
"""

EXAMPLES = """
Expand All @@ -150,6 +172,14 @@
- acl rule protocol testACL 1 any
- acl rule direction testACL 3 in
before: acl delete testACL

- name: configurable backup path
aireos_config:
backup: yes
lines: sysname testDevice
backup_options:
filename: backup.cfg
dir_path: /home/user
"""

RETURN = """
Expand Down Expand Up @@ -209,6 +239,10 @@ def save_config(module, result):
def main():
""" main entry point for module execution
"""
backup_spec = dict(
filename=dict(),
dir_path=dict(type='path')
)
argument_spec = dict(
src=dict(type='path'),

Expand All @@ -223,6 +257,7 @@ def main():
intended_config=dict(),

backup=dict(type='bool', default=False),
backup_options=dict(type='dict', options=backup_spec),

# save is deprecated as of 2.7, use save_when instead
save=dict(type='bool', default=False, removed_in_version='2.11'),
Expand Down
41 changes: 38 additions & 3 deletions lib/ansible/modules/network/aruba/aruba_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
description:
- This argument will cause the module to create a full backup of
the current C(running-config) from the remote device before any
changes are made. The backup file is written to the C(backup)
folder in the playbook root directory. If the directory does not
exist, it is created.
changes are made. If the C(backup_options) value is not given,
the backup file is written to the C(backup) folder in the playbook
root directory. If the directory does not exist, it is created.
type: bool
default: 'no'
running_config:
Expand Down Expand Up @@ -152,6 +152,28 @@
type: bool
default: 'yes'
version_added: "2.5"
backup_options:
description:
- This is a dict object containing configurable options related to backup file path.
The value of this option is read only when C(backup) is set to I(yes), if C(backup) is set
to I(no) this option will be silently ignored.
suboptions:
filename:
description:
- The filename to be used to store the backup configuration. If the the filename
is not given it will be generated based on the hostname, current time and date
in format defined by <hostname>_config.<current-date>@<current-time>
dir_path:
description:
- This option provides the path ending with directory name in which the backup
configuration file will be stored. If the directory does not exist it will be first
created and the filename is either the value of C(filename) or default filename
as described in C(filename) options description. If the path value is not given
in that case a I(backup) directory will be created in the current working directory
and backup configuration will be copied in C(filename) within I(backup) directory.
type: path
type: dict
version_added: "2.8"
"""

EXAMPLES = """
Expand Down Expand Up @@ -179,6 +201,14 @@
parents: ip access-list standard 1
before: no ip access-list standard 1
match: exact

- name: configurable backup path
aruba_config:
backup: yes
lines: hostname {{ inventory_hostname }}
backup_options:
filename: backup.cfg
dir_path: /home/user
"""

RETURN = """
Expand Down Expand Up @@ -241,6 +271,10 @@ def save_config(module, result):
def main():
""" main entry point for module execution
"""
backup_spec = dict(
filename=dict(),
dir_path=dict(type='path')
)
argument_spec = dict(
src=dict(type='path'),

Expand All @@ -257,6 +291,7 @@ def main():
intended_config=dict(),

backup=dict(type='bool', default=False),
backup_options=dict(type='dict', options=backup_spec),

save_when=dict(choices=['always', 'never', 'modified', 'changed'], default='never'),

Expand Down
42 changes: 39 additions & 3 deletions lib/ansible/modules/network/asa/asa_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
description:
- This argument will cause the module to create a full backup of
the current C(running-config) from the remote device before any
changes are made. The backup file is written to the C(backup)
folder in the playbook root directory. If the directory does not
exist, it is created.
changes are made. If the C(backup_options) value is not given,
the backup file is written to the C(backup) folder in the
playbook root directory. If the directory does not exist, it is created.
type: bool
default: 'no'
config:
Expand Down Expand Up @@ -119,6 +119,28 @@
running. If check mode is specified, this argument is ignored.
type: bool
default: 'no'
backup_options:
description:
- This is a dict object containing configurable options related to backup file path.
The value of this option is read only when C(backup) is set to I(yes), if C(backup) is set
to I(no) this option will be silently ignored.
suboptions:
filename:
description:
- The filename to be used to store the backup configuration. If the the filename
is not given it will be generated based on the hostname, current time and date
in format defined by <hostname>_config.<current-date>@<current-time>
dir_path:
description:
- This option provides the path ending with directory name in which the backup
configuration file will be stored. If the directory does not exist it will be first
created and the filename is either the value of C(filename) or default filename
as described in C(filename) options description. If the path value is not given
in that case a I(backup) directory will be created in the current working directory
and backup configuration will be copied in C(filename) within I(backup) directory.
type: path
type: dict
version_added: "2.8"
"""

EXAMPLES = """
Expand Down Expand Up @@ -207,6 +229,15 @@
debug:
var: interface

- name: configurable backup path
asa_config:
lines:
- access-group cloud-acl_access_in in interface cloud13
provider: "{{ cli }}"
backup: yes
backup_options:
filename: backup.cfg
dir_path: /home/user
"""

RETURN = """
Expand Down Expand Up @@ -282,6 +313,10 @@ def run(module, result):
def main():
""" main entry point for module execution
"""
backup_spec = dict(
filename=dict(),
dir_path=dict(type='path')
)
argument_spec = dict(
src=dict(type='path'),

Expand All @@ -293,6 +328,7 @@ def main():

match=dict(default='line', choices=['line', 'strict', 'exact', 'none']),
replace=dict(default='line', choices=['line', 'block']),
backup_options=dict(type='dict', options=backup_spec),

config=dict(),
defaults=dict(type='bool', default=False),
Expand Down
43 changes: 39 additions & 4 deletions lib/ansible/modules/network/cli/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
description:
- This argument will cause the module to create a full backup of
the current running config from the remote device before any
changes are made. The backup file is written to the C(backup)
folder in the playbook root directory or role root directory, if
playbook is part of an ansible role. If the directory does not exist,
it is created.
changes are made. If the C(backup_options) value is not given,
the backup file is written to the C(backup) folder in the playbook
root directory or role root directory, if playbook is part of an
ansible role. If the directory does not exist, it is created.
type: bool
default: 'no'
version_added: "2.8"
Expand Down Expand Up @@ -118,6 +118,28 @@
a list of regular expressions or exact line matches.
Note that this parameter will be ignored if the platform has onbox
diff support.
backup_options:
description:
- This is a dict object containing configurable options related to backup file path.
The value of this option is read only when C(backup) is set to I(yes), if C(backup) is set
to I(no) this option will be silently ignored.
suboptions:
filename:
description:
- The filename to be used to store the backup configuration. If the the filename
is not given it will be generated based on the hostname, current time and date
in format defined by <hostname>_config.<current-date>@<current-time>
dir_path:
description:
- This option provides the path ending with directory name in which the backup
configuration file will be stored. If the directory does not exist it will be first
created and the filename is either the value of C(filename) or default filename
as described in C(filename) options description. If the path value is not given
in that case a I(backup) directory will be created in the current working directory
and backup configuration will be copied in C(filename) within I(backup) directory.
type: path
type: dict
version_added: "2.8"
"""

EXAMPLES = """
Expand All @@ -143,6 +165,14 @@
cli_config:
config: set system host-name foo
commit_comment: this is a test

- name: configurable backup path
cli_config:
config: "{{ lookup('template', 'basic/config.j2') }}"
backup: yes
backup_options:
filename: backup.cfg
dir_path: /home/user
"""

RETURN = """
Expand Down Expand Up @@ -299,8 +329,13 @@ def run(module, capabilities, connection, candidate, running):
def main():
"""main entry point for execution
"""
backup_spec = dict(
filename=dict(),
dir_path=dict(type='path')
)
argument_spec = dict(
backup=dict(default=False, type='bool'),
backup_options=dict(type='dict', options=backup_spec),
config=dict(type='str'),
commit=dict(type='bool'),
replace=dict(type='str'),
Expand Down
42 changes: 39 additions & 3 deletions lib/ansible/modules/network/cloudengine/ce_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@
description:
- This argument will cause the module to create a full backup of
the current C(current-configuration) from the remote device before any
changes are made. The backup file is written to the C(backup)
folder in the playbook root directory. If the directory does not
exist, it is created.
changes are made. If the C(backup_options) value is not given,
the backup file is written to the C(backup) folder in the playbook
root directory. If the directory does not exist, it is created.
type: bool
default: 'no'
config:
Expand Down Expand Up @@ -125,6 +125,28 @@
return changed.
type: bool
default: 'no'
backup_options:
description:
- This is a dict object containing configurable options related to backup file path.
The value of this option is read only when C(backup) is set to I(yes), if C(backup) is set
to I(no) this option will be silently ignored.
suboptions:
filename:
description:
- The filename to be used to store the backup configuration. If the the filename
is not given it will be generated based on the hostname, current time and date
in format defined by <hostname>_config.<current-date>@<current-time>
dir_path:
description:
- This option provides the path ending with directory name in which the backup
configuration file will be stored. If the directory does not exist it will be first
created and the filename is either the value of C(filename) or default filename
as described in C(filename) options description. If the path value is not given
in that case a I(backup) directory will be created in the current working directory
and backup configuration will be copied in C(filename) within I(backup) directory.
type: path
type: dict
version_added: "2.8"
"""

EXAMPLES = """
Expand Down Expand Up @@ -174,6 +196,15 @@
before: undo acl 2000
replace: block
provider: "{{ cli }}"

- name: configurable backup path
ce_config:
lines: sysname {{ inventory_hostname }}
provider: "{{ cli }}"
backup: yes
backup_options:
filename: backup.cfg
dir_path: /home/user
"""

RETURN = """
Expand Down Expand Up @@ -254,6 +285,10 @@ def run(module, result):
def main():
""" main entry point for module execution
"""
backup_spec = dict(
filename=dict(),
dir_path=dict(type='path')
)
argument_spec = dict(
src=dict(type='path'),

Expand All @@ -269,6 +304,7 @@ def main():
defaults=dict(type='bool', default=False),

backup=dict(type='bool', default=False),
backup_options=dict(type='dict', options=backup_spec),
save=dict(type='bool', default=False),
)

Expand Down