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

Verbose config extra fact #23

Merged
merged 16 commits into from
Mar 29, 2021
1 change: 1 addition & 0 deletions changelogs/fragments/1.2.0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release_summary: This release add nonverbose idempotent config in facts
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions changelogs/fragments/23-indempotent_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- fact - add fact _ansible_net_config_nonverbose_ to get indempotent config (no date, no verbose)
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 13 additions & 1 deletion plugins/modules/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,26 @@ def to_megabytes(self, data):

class Config(FactsBase):

COMMANDS = ['/export verbose']
COMMANDS = [
'/export verbose',
'/export'
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
]

RM_DATE_RE = re.compile(r'^# [a-z0-9/][a-z0-9/]* [0-9:]* by RouterOS')

def populate(self):
super(Config, self).populate()

data = self.responses[0]
if data:
self.facts['config'] = data

data = self.responses[1]
if data:
# remove datetime
data = re.sub(self.RM_DATE_RE, r'# RouterOS', data)
self.facts['config_nonverbose'] = data
felixfontein marked this conversation as resolved.
Show resolved Hide resolved


class Interfaces(FactsBase):

Expand Down
24 changes: 24 additions & 0 deletions tests/unit/plugins/modules/fixtures/facts/export
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# sep/25/2018 10:10:52 by RouterOS 6.42.5
# software id = 9EER-511K
#
#
#
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/tool user-manager customer
set admin access=own-routers,own-users,own-profiles,own-limits,config-payment-gw
/ip address
add address=192.168.88.1/24 comment=defconf interface=ether1 network=192.168.88.0
/ip dhcp-client
add dhcp-options=hostname,clientid disabled=no interface=ether1
/system lcd page
set time disabled=yes display-time=5s
set resources disabled=yes display-time=5s
set uptime disabled=yes display-time=5s
set packets disabled=yes display-time=5s
set bits disabled=yes display-time=5s
set version disabled=yes display-time=5s
set identity disabled=yes display-time=5s
set ether1 disabled=yes display-time=5s
/tool user-manager database
set db-path=user-manager
5 changes: 5 additions & 0 deletions tests/unit/plugins/modules/test_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ def test_facts_hardware(self):
def test_facts_config(self):
set_module_args(dict(gather_subset='config'))
result = self.execute_module()
print(result['ansible_facts'])
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
self.assertIsInstance(
result['ansible_facts']['ansible_net_config'], str
)

self.assertIsInstance(
result['ansible_facts']['ansible_net_config_nonverbose'], str
)

def test_facts_interfaces(self):
set_module_args(dict(gather_subset='interfaces'))
result = self.execute_module()
Expand Down