diff --git a/lib/ansible/modules/network/ios/ios_user.py b/lib/ansible/modules/network/ios/ios_user.py index da71361520..673eea848a 100644 --- a/lib/ansible/modules/network/ios/ios_user.py +++ b/lib/ansible/modules/network/ios/ios_user.py @@ -181,7 +181,8 @@ def user_del_cmd(username): return json.dumps({ 'command': 'no username %s' % username, 'prompt': 'This operation will remove all username related configurations with same name', - 'answer': 'y' + 'answer': 'y', + 'newline': False, }) diff --git a/lib/ansible/plugins/action/ios_config.py b/lib/ansible/plugins/action/ios_config.py index fe457bc8c9..5471bcb455 100644 --- a/lib/ansible/plugins/action/ios_config.py +++ b/lib/ansible/plugins/action/ios_config.py @@ -40,7 +40,7 @@ class ActionModule(_ActionModule): try: self._handle_template() except ValueError as exc: - return dict(failed=True, msg=exc.message) + return dict(failed=True, msg=to_text(exc)) result = super(ActionModule, self).run(tmp, task_vars) @@ -54,7 +54,7 @@ class ActionModule(_ActionModule): # strip out any keys that have two leading and two trailing # underscore characters - for key in result.keys(): + for key in list(result.keys()): if PRIVATE_KEYS_RE.match(key): del result[key] diff --git a/lib/ansible/plugins/cliconf/ios.py b/lib/ansible/plugins/cliconf/ios.py index 9f53126f2b..40cfc18ff0 100644 --- a/lib/ansible/plugins/cliconf/ios.py +++ b/lib/ansible/plugins/cliconf/ios.py @@ -64,8 +64,8 @@ class Cliconf(CliconfBase): @enable_mode def edit_config(self, command): - for cmd in chain([b'configure terminal'], to_list(command), [b'end']): - self.send_command(cmd) + for cmd in chain(['configure terminal'], to_list(command), ['end']): + self.send_command(to_bytes(cmd)) def get(self, command, prompt=None, answer=None, sendonly=False): return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly) diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index b67c4b55e3..7c47ddf14e 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -121,8 +121,10 @@ class Connection(ConnectionBase): try: cmd = json.loads(to_text(cmd, errors='surrogate_or_strict')) kwargs = {'command': to_bytes(cmd['command'], errors='surrogate_or_strict')} - for key in ('prompt', 'answer', 'sendonly'): - if cmd.get(key) is not None: + for key in ('prompt', 'answer', 'sendonly', 'newline'): + if cmd.get(key) is True or cmd.get(key) is False: + kwargs[key] = cmd[key] + elif cmd.get(key) is not None: kwargs[key] = to_bytes(cmd[key], errors='surrogate_or_strict') return self.send(**kwargs) except ValueError: @@ -257,7 +259,7 @@ class Connection(ConnectionBase): self._connected = False display.debug("ssh connection has been closed successfully") - def receive(self, command=None, prompts=None, answer=None): + def receive(self, command=None, prompts=None, answer=None, newline=True): ''' Handles receiving of output from command ''' @@ -279,14 +281,14 @@ class Connection(ConnectionBase): window = self._strip(recv.read()) if prompts and not handled: - handled = self._handle_prompt(window, prompts, answer) + handled = self._handle_prompt(window, prompts, answer, newline) if self._find_prompt(window): self._last_response = recv.getvalue() resp = self._strip(self._last_response) return self._sanitize(resp, command) - def send(self, command, prompt=None, answer=None, sendonly=False): + def send(self, command, prompt=None, answer=None, newline=True, sendonly=False): ''' Sends the command to the device in the opened shell ''' @@ -295,7 +297,7 @@ class Connection(ConnectionBase): self._ssh_shell.sendall(b'%s\r' % command) if sendonly: return - response = self.receive(command, prompt, answer) + response = self.receive(command, prompt, answer, newline) return to_text(response, errors='surrogate_or_strict') except (socket.timeout, AttributeError): display.vvvv(traceback.format_exc(), host=self._play_context.remote_addr) @@ -309,7 +311,7 @@ class Connection(ConnectionBase): data = regex.sub(b'', data) return data - def _handle_prompt(self, resp, prompts, answer): + def _handle_prompt(self, resp, prompts, answer, newline): ''' Matches the command prompt and responds @@ -325,7 +327,9 @@ class Connection(ConnectionBase): for regex in prompts: match = regex.search(resp) if match: - self._ssh_shell.sendall(b'%s\r' % answer) + self._ssh_shell.sendall(b'%s' % answer) + if newline: + self._ssh_shell.sendall(b'\r') return True return False diff --git a/test/integration/targets/ios_banner/tasks/cli.yaml b/test/integration/targets/ios_banner/tasks/cli.yaml index d675462dd0..a6f7ae0351 100644 --- a/test/integration/targets/ios_banner/tasks/cli.yaml +++ b/test/integration/targets/ios_banner/tasks/cli.yaml @@ -4,12 +4,19 @@ paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" register: test_cases + delegate_to: localhost - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_banner/tests/cli/basic-login.yaml b/test/integration/targets/ios_banner/tests/cli/basic-login.yaml index 3dd094a3b5..473694c825 100644 --- a/test/integration/targets/ios_banner/tests/cli/basic-login.yaml +++ b/test/integration/targets/ios_banner/tests/cli/basic-login.yaml @@ -5,6 +5,7 @@ banner: login state: absent authorize: yes + become: yes - name: Set login ios_banner: @@ -15,6 +16,7 @@ string state: present authorize: yes + become: yes register: result - debug: @@ -34,6 +36,7 @@ string state: present authorize: yes + become: yes register: result - assert: diff --git a/test/integration/targets/ios_banner/tests/cli/basic-motd.yaml b/test/integration/targets/ios_banner/tests/cli/basic-motd.yaml index 319f488d5b..1c1dd21386 100644 --- a/test/integration/targets/ios_banner/tests/cli/basic-motd.yaml +++ b/test/integration/targets/ios_banner/tests/cli/basic-motd.yaml @@ -5,6 +5,7 @@ banner: motd state: absent authorize: yes + become: yes - name: Set motd ios_banner: @@ -15,6 +16,7 @@ string state: present authorize: yes + become: yes register: result - debug: @@ -34,6 +36,7 @@ string state: present authorize: yes + become: yes register: result - assert: diff --git a/test/integration/targets/ios_banner/tests/cli/basic-no-login.yaml b/test/integration/targets/ios_banner/tests/cli/basic-no-login.yaml index 69a549c8d4..f034872f76 100644 --- a/test/integration/targets/ios_banner/tests/cli/basic-no-login.yaml +++ b/test/integration/targets/ios_banner/tests/cli/basic-no-login.yaml @@ -7,12 +7,14 @@ over multiple lines state: present authorize: yes + become: yes - name: remove login ios_banner: banner: login state: absent authorize: yes + become: yes register: result - debug: @@ -28,6 +30,7 @@ banner: login state: absent authorize: yes + become: yes register: result - assert: diff --git a/test/integration/targets/ios_command/tasks/cli.yaml b/test/integration/targets/ios_command/tasks/cli.yaml index 46d86dd698..a6f7ae0351 100644 --- a/test/integration/targets/ios_command/tasks/cli.yaml +++ b/test/integration/targets/ios_command/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_command/tests/cli/bad_operator.yaml b/test/integration/targets/ios_command/tests/cli/bad_operator.yaml index 5563afaf65..66757a6644 100644 --- a/test/integration/targets/ios_command/tests/cli/bad_operator.yaml +++ b/test/integration/targets/ios_command/tests/cli/bad_operator.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/bad_operator.yaml" +- debug: msg="START cli/bad_operator.yaml on connection={{ ansible_connection }}" - name: test bad operator ios_command: @@ -9,6 +9,7 @@ authorize: yes wait_for: - "result[0] contains 'Description: Foo'" + become: yes register: result ignore_errors: yes @@ -17,4 +18,4 @@ - "result.failed == true" - "result.msg is defined" -- debug: msg="END cli/bad_operator.yaml" +- debug: msg="END cli/bad_operator.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_command/tests/cli/contains.yaml b/test/integration/targets/ios_command/tests/cli/contains.yaml index 6f1b67cb23..3ab19fa500 100644 --- a/test/integration/targets/ios_command/tests/cli/contains.yaml +++ b/test/integration/targets/ios_command/tests/cli/contains.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/contains.yaml" +- debug: msg="START cli/contains.yaml on connection={{ ansible_connection }}" - name: test contains operator ios_command: @@ -10,6 +10,7 @@ wait_for: - "result[0] contains Cisco" - "result[1] contains Loopback888" + become: yes register: result - assert: @@ -17,4 +18,4 @@ - "result.changed == false" - "result.stdout is defined" -- debug: msg="END cli/contains.yaml" +- debug: msg="END cli/contains.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_command/tests/cli/invalid.yaml b/test/integration/targets/ios_command/tests/cli/invalid.yaml index fb147226bd..b5a63b1e7f 100644 --- a/test/integration/targets/ios_command/tests/cli/invalid.yaml +++ b/test/integration/targets/ios_command/tests/cli/invalid.yaml @@ -1,10 +1,11 @@ --- -- debug: msg="START cli/invalid.yaml" +- debug: msg="START cli/invalid.yaml on connection={{ ansible_connection }}" - name: run invalid command ios_command: commands: show foo authorize: yes + become: yes register: result ignore_errors: yes @@ -18,6 +19,7 @@ - show version - show foo authorize: yes + become: yes register: result ignore_errors: yes @@ -25,4 +27,4 @@ that: - "result.failed" -- debug: msg="END cli/invalid.yaml" +- debug: msg="END cli/invalid.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_command/tests/cli/output.yaml b/test/integration/targets/ios_command/tests/cli/output.yaml index 2471eb85d8..5052625801 100644 --- a/test/integration/targets/ios_command/tests/cli/output.yaml +++ b/test/integration/targets/ios_command/tests/cli/output.yaml @@ -1,11 +1,12 @@ --- -- debug: msg="START cli/output.yaml" +- debug: msg="START cli/output.yaml on connection={{ ansible_connection }}" - name: get output for single command ios_command: commands: - show version authorize: yes + become: yes register: result - assert: @@ -19,6 +20,7 @@ - show version - show interfaces authorize: yes + become: yes register: result - assert: @@ -27,4 +29,4 @@ - "result.stdout is defined" - "result.stdout | length == 2" -- debug: msg="END cli/output.yaml" +- debug: msg="END cli/output.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_command/tests/cli/timeout.yaml b/test/integration/targets/ios_command/tests/cli/timeout.yaml index 183be11fd3..b92882dff9 100644 --- a/test/integration/targets/ios_command/tests/cli/timeout.yaml +++ b/test/integration/targets/ios_command/tests/cli/timeout.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/timeout.yaml" +- debug: msg="START cli/timeout.yaml on connection={{ ansible_connection }}" - name: test bad condition ios_command: @@ -8,6 +8,7 @@ authorize: yes wait_for: - "result[0] contains bad_value_string" + become: yes register: result ignore_errors: yes @@ -16,4 +17,4 @@ - "result.failed == true" - "result.msg is defined" -- debug: msg="END cli/timeout.yaml" +- debug: msg="END cli/timeout.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tasks/cli.yaml b/test/integration/targets/ios_config/tasks/cli.yaml index 46d86dd698..a6f7ae0351 100644 --- a/test/integration/targets/ios_config/tasks/cli.yaml +++ b/test/integration/targets/ios_config/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_config/tests/cli/backup.yaml b/test/integration/targets/ios_config/tests/cli/backup.yaml index 1c485d33c1..0ba544c361 100644 --- a/test/integration/targets/ios_config/tests/cli/backup.yaml +++ b/test/integration/targets/ios_config/tests/cli/backup.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/backup.yaml" +- debug: msg="START cli/backup.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -10,13 +10,14 @@ - interface Loopback999 match: none authorize: yes + become: yes - name: collect any backup files find: paths: "{{ role_path }}/backup" pattern: "{{ inventory_hostname_short }}_config*" register: backup_files - delegate_to: localhost + connection: local - name: delete backup files file: @@ -29,6 +30,7 @@ src: basic/config.j2 backup: yes authorize: yes + become: yes register: result - assert: @@ -42,10 +44,10 @@ paths: "{{ role_path }}/backup" pattern: "{{ inventory_hostname_short }}_config*" register: backup_files - delegate_to: localhost + connection: local - assert: that: - "backup_files.files is defined" -- debug: msg="END cli/backup.yaml" +- debug: msg="END cli/backup.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/defaults.yaml b/test/integration/targets/ios_config/tests/cli/defaults.yaml index eaea5588dd..5e62eb74a5 100644 --- a/test/integration/targets/ios_config/tests/cli/defaults.yaml +++ b/test/integration/targets/ios_config/tests/cli/defaults.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/defaults.yaml" +- debug: msg="START cli/defaults.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -10,12 +10,14 @@ - interface Loopback999 match: none authorize: yes + become: yes - name: configure device with defaults included ios_config: src: defaults/config.j2 defaults: yes authorize: yes + become: yes register: result - debug: var=result @@ -31,6 +33,7 @@ src: defaults/config.j2 defaults: yes authorize: yes + become: yes register: result - debug: var=result @@ -45,6 +48,7 @@ lines: - mac-address-table notification mac-move authorize: yes + become: yes ignore_errors: yes - name: show interfaces brief to ensure deivce goes to valid prompt @@ -52,6 +56,7 @@ commands: - show interfaces authorize: yes + become: yes register: result - assert: @@ -59,4 +64,4 @@ - "result.changed == false" - "result.stdout is defined" -- debug: msg="END cli/defaults.yaml" +- debug: msg="END cli/defaults.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/save.yaml b/test/integration/targets/ios_config/tests/cli/save.yaml index 25d47852b0..3242b8b802 100644 --- a/test/integration/targets/ios_config/tests/cli/save.yaml +++ b/test/integration/targets/ios_config/tests/cli/save.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/save.yaml" +- debug: msg="START cli/save.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -10,12 +10,14 @@ - interface Loopback999 match: none authorize: yes + become: yes - name: save config ios_config: save: true authorize: yes + become: yes register: result # FIXME https://github.com/ansible/ansible-modules-core/issues/5008 ignore_errors: true @@ -30,6 +32,7 @@ ios_config: save: true authorize: yes + become: yes register: result # FIXME https://github.com/ansible/ansible-modules-core/issues/5008 ignore_errors: true @@ -41,6 +44,7 @@ - "no ip http server" save_when: modified authorize: yes + become: yes register: result - name: save should always run @@ -50,6 +54,7 @@ - "ip http server" save_when: modified authorize: yes + become: yes register: result - assert: @@ -61,6 +66,7 @@ lines: - "no ip http server" authorize: yes + become: yes register: result -- debug: msg="END cli/save.yaml" +- debug: msg="END cli/save.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/src_basic.yaml b/test/integration/targets/ios_config/tests/cli/src_basic.yaml index 2ed68179f0..a8da2a0b4e 100644 --- a/test/integration/targets/ios_config/tests/cli/src_basic.yaml +++ b/test/integration/targets/ios_config/tests/cli/src_basic.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/src_basic.yaml" +- debug: msg="START cli/src_basic.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -10,11 +10,13 @@ - interface Loopback999 match: none authorize: yes + become: yes - name: configure device with config ios_config: src: basic/config.j2 authorize: yes + become: yes register: result - name: debug, remove me @@ -31,6 +33,7 @@ ios_config: src: basic/config.j2 authorize: yes + become: yes register: result - assert: @@ -40,4 +43,4 @@ # FIXME Bug https://github.com/ansible/ansible/issues/19382 # - "result.updates is not defined" -- debug: msg="END cli/src_basic.yaml" +- debug: msg="END cli/src_basic.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/src_invalid.yaml b/test/integration/targets/ios_config/tests/cli/src_invalid.yaml index cd8e9e5be4..296a2ee8a8 100644 --- a/test/integration/targets/ios_config/tests/cli/src_invalid.yaml +++ b/test/integration/targets/ios_config/tests/cli/src_invalid.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/src_invalid.yaml" +- debug: msg="START cli/src_invalid.yaml on connection={{ ansible_connection }}" # Defend https://github.com/ansible/ansible-modules-core/issues/4797 @@ -7,6 +7,7 @@ ios_config: src: basic/foobar.j2 authorize: yes + become: yes register: result ignore_errors: yes @@ -16,4 +17,4 @@ - "result.failed == true" - "result.msg == 'path specified in src not found'" -- debug: msg="END cli/src_invalid.yaml" +- debug: msg="END cli/src_invalid.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/src_match_none.yaml b/test/integration/targets/ios_config/tests/cli/src_match_none.yaml index 70677c231f..0b3078c811 100644 --- a/test/integration/targets/ios_config/tests/cli/src_match_none.yaml +++ b/test/integration/targets/ios_config/tests/cli/src_match_none.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/src_match_none.yaml" +- debug: msg="START cli/src_match_none.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -10,12 +10,14 @@ - interface Loopback999 match: none authorize: yes + become: yes - name: configure device with config ios_config: src: basic/config.j2 match: none authorize: yes + become: yes register: result - assert: @@ -29,6 +31,7 @@ ios_config: src: basic/config.j2 authorize: yes + become: yes register: result - assert: @@ -38,4 +41,4 @@ - "result.changed == false" - "result.updates is not defined" -- debug: msg="END cli/src_match_none.yaml" +- debug: msg="END cli/src_match_none.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/sublevel.yaml b/test/integration/targets/ios_config/tests/cli/sublevel.yaml index 184d282a75..06a49e660a 100644 --- a/test/integration/targets/ios_config/tests/cli/sublevel.yaml +++ b/test/integration/targets/ios_config/tests/cli/sublevel.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/sublevel.yaml" +- debug: msg="START cli/sublevel.yaml on connection={{ ansible_connection }}" - name: setup test ios_config: @@ -8,12 +8,14 @@ - 'no ip access-list standard test' match: none authorize: yes + become: yes - name: configure sub level command ios_config: lines: ['permit ip any any log'] parents: ['ip access-list extended test'] authorize: yes + become: yes register: result - assert: @@ -27,6 +29,7 @@ lines: ['permit ip any any log'] parents: ['ip access-list extended test'] authorize: yes + become: yes register: result - assert: @@ -39,5 +42,6 @@ - 'no ip access-list extended test' match: none authorize: yes + become: yes -- debug: msg="END cli/sublevel.yaml" +- debug: msg="END cli/sublevel.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/sublevel_block.yaml b/test/integration/targets/ios_config/tests/cli/sublevel_block.yaml index 252c15c5da..f54f4da4ab 100644 --- a/test/integration/targets/ios_config/tests/cli/sublevel_block.yaml +++ b/test/integration/targets/ios_config/tests/cli/sublevel_block.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/sublevel_block.yaml" +- debug: msg="START cli/sublevel_block.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -12,6 +12,7 @@ after: ['exit'] authorize: yes match: none + become: yes - name: configure sub level command using block resplace ios_config: @@ -24,6 +25,7 @@ replace: block after: ['exit'] authorize: yes + become: yes register: result - assert: @@ -46,6 +48,7 @@ replace: block after: ['exit'] authorize: yes + become: yes register: result - assert: @@ -58,5 +61,6 @@ - no ip access-list extended test match: none authorize: yes + become: yes -- debug: msg="END cli/sublevel_block.yaml" +- debug: msg="END cli/sublevel_block.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/sublevel_exact.yaml b/test/integration/targets/ios_config/tests/cli/sublevel_exact.yaml index 8821f197ad..c407b8fecc 100644 --- a/test/integration/targets/ios_config/tests/cli/sublevel_exact.yaml +++ b/test/integration/targets/ios_config/tests/cli/sublevel_exact.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/sublevel_exact.yaml" +- debug: msg="START cli/sublevel_exact.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -14,6 +14,7 @@ after: exit match: none authorize: yes + become: yes - name: configure sub level command using exact match ios_config: @@ -27,6 +28,7 @@ after: exit match: exact authorize: yes + become: yes register: result - assert: @@ -49,6 +51,7 @@ parents: ip access-list extended test match: exact authorize: yes + become: yes register: result - assert: @@ -61,5 +64,6 @@ - no ip access-list extended test match: none authorize: yes + become: yes -- debug: msg="END cli/sublevel_exact.yaml" +- debug: msg="END cli/sublevel_exact.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/sublevel_strict.yaml b/test/integration/targets/ios_config/tests/cli/sublevel_strict.yaml index e047680681..9a11c3631f 100644 --- a/test/integration/targets/ios_config/tests/cli/sublevel_strict.yaml +++ b/test/integration/targets/ios_config/tests/cli/sublevel_strict.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/sublevel_strict.yaml" +- debug: msg="START cli/sublevel_strict.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -13,6 +13,7 @@ before: no ip access-list extended test match: none authorize: yes + become: yes - name: configure sub level command using strict match ios_config: @@ -24,6 +25,7 @@ parents: ip access-list extended test match: strict authorize: yes + become: yes register: result - assert: @@ -40,6 +42,7 @@ after: exit match: strict authorize: yes + become: yes register: result - assert: @@ -57,5 +60,6 @@ lines: no ip access-list extended test match: none authorize: yes + become: yes -- debug: msg="END cli/sublevel_strict.yaml" +- debug: msg="END cli/sublevel_strict.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/toplevel.yaml b/test/integration/targets/ios_config/tests/cli/toplevel.yaml index db8bf7b642..14fb3df462 100644 --- a/test/integration/targets/ios_config/tests/cli/toplevel.yaml +++ b/test/integration/targets/ios_config/tests/cli/toplevel.yaml @@ -1,16 +1,18 @@ --- -- debug: msg="START cli/toplevel.yaml" +- debug: msg="START cli/toplevel.yaml on connection={{ ansible_connection }}" - name: setup ios_config: lines: ['hostname {{ shorter_hostname }}'] match: none authorize: yes + become: yes - name: configure top level command ios_config: lines: ['hostname foo'] authorize: yes + become: yes register: result - assert: @@ -22,6 +24,7 @@ ios_config: lines: ['hostname foo'] authorize: yes + become: yes register: result - assert: @@ -33,5 +36,6 @@ lines: ['hostname {{ shorter_hostname }}'] match: none authorize: yes + become: yes -- debug: msg="END cli/toplevel.yaml" +- debug: msg="END cli/toplevel.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/toplevel_after.yaml b/test/integration/targets/ios_config/tests/cli/toplevel_after.yaml index 0fd0f982d9..a79ea407d2 100644 --- a/test/integration/targets/ios_config/tests/cli/toplevel_after.yaml +++ b/test/integration/targets/ios_config/tests/cli/toplevel_after.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/toplevel_after.yaml" +- debug: msg="START cli/toplevel_after.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -8,12 +8,14 @@ - "hostname {{ shorter_hostname }}" match: none authorize: yes + become: yes - name: configure top level command with before ios_config: lines: ['hostname foo'] after: ['snmp-server contact bar'] authorize: yes + become: yes register: result - assert: @@ -27,6 +29,7 @@ lines: ['hostname foo'] after: ['snmp-server contact foo'] authorize: yes + become: yes register: result - assert: @@ -40,5 +43,6 @@ - "hostname {{ shorter_hostname }}" match: none authorize: yes + become: yes -- debug: msg="END cli/toplevel_after.yaml" +- debug: msg="END cli/toplevel_after.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/toplevel_before.yaml b/test/integration/targets/ios_config/tests/cli/toplevel_before.yaml index f5038e79e6..ee80d7d648 100644 --- a/test/integration/targets/ios_config/tests/cli/toplevel_before.yaml +++ b/test/integration/targets/ios_config/tests/cli/toplevel_before.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/toplevel_before.yaml" +- debug: msg="START cli/toplevel_before.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -8,12 +8,14 @@ - "hostname {{ shorter_hostname }}" match: none authorize: yes + become: yes - name: configure top level command with before ios_config: lines: ['hostname foo'] before: ['snmp-server contact bar'] authorize: yes + become: yes register: result - assert: @@ -27,6 +29,7 @@ lines: ['hostname foo'] before: ['snmp-server contact foo'] authorize: yes + become: yes register: result - assert: @@ -40,5 +43,6 @@ - "hostname {{ shorter_hostname }}" match: none authorize: yes + become: yes -- debug: msg="END cli/toplevel_before.yaml" +- debug: msg="END cli/toplevel_before.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_config/tests/cli/toplevel_nonidempotent.yaml b/test/integration/targets/ios_config/tests/cli/toplevel_nonidempotent.yaml index 749e6e4183..3fed970a8c 100644 --- a/test/integration/targets/ios_config/tests/cli/toplevel_nonidempotent.yaml +++ b/test/integration/targets/ios_config/tests/cli/toplevel_nonidempotent.yaml @@ -1,17 +1,19 @@ --- -- debug: msg="START cli/toplevel_nonidempotent.yaml" +- debug: msg="START cli/toplevel_nonidempotent.yaml on connection={{ ansible_connection }}" - name: setup ios_config: lines: ['hostname {{ shorter_hostname }}'] match: none authorize: yes + become: yes - name: configure top level command ios_config: lines: ['hostname foo'] match: strict authorize: yes + become: yes register: result - assert: @@ -24,6 +26,7 @@ lines: ['hostname foo'] match: strict authorize: yes + become: yes register: result - assert: @@ -35,5 +38,6 @@ lines: ['hostname {{ shorter_hostname }}'] match: none authorize: yes + become: yes -- debug: msg="END cli/toplevel_nonidempotent.yaml" +- debug: msg="END cli/toplevel_nonidempotent.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_facts/tasks/cli.yaml b/test/integration/targets/ios_facts/tasks/cli.yaml index 46d86dd698..a6f7ae0351 100644 --- a/test/integration/targets/ios_facts/tasks/cli.yaml +++ b/test/integration/targets/ios_facts/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_facts/tests/cli/all_facts.yaml b/test/integration/targets/ios_facts/tests/cli/all_facts.yaml index b707681235..2c6dfad3d9 100644 --- a/test/integration/targets/ios_facts/tests/cli/all_facts.yaml +++ b/test/integration/targets/ios_facts/tests/cli/all_facts.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/all_facts.yaml" +- debug: msg="START cli/all_facts.yaml on connection={{ ansible_connection }}" - name: test getting all facts @@ -7,6 +7,7 @@ gather_subset: - all authorize: yes + become: yes register: result @@ -28,4 +29,4 @@ - "result.ansible_facts.ansible_net_memfree_mb > 1" - "result.ansible_facts.ansible_net_memtotal_mb > 1" -- debug: msg="END cli/all_facts.yaml" +- debug: msg="END cli/all_facts.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_facts/tests/cli/default_facts.yaml b/test/integration/targets/ios_facts/tests/cli/default_facts.yaml index 1c9370fc10..57f456f663 100644 --- a/test/integration/targets/ios_facts/tests/cli/default_facts.yaml +++ b/test/integration/targets/ios_facts/tests/cli/default_facts.yaml @@ -1,10 +1,11 @@ --- -- debug: msg="START cli/default_facts.yaml" +- debug: msg="START cli/default_facts.yaml on connection={{ ansible_connection }}" - name: test getting default facts ios_facts: authorize: yes + become: yes register: result - assert: @@ -28,4 +29,4 @@ # ... and not present - "result.ansible_facts.ansible_net_config is not defined" # config -- debug: msg="END cli/default.yaml" +- debug: msg="END cli/default.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_facts/tests/cli/invalid_subset.yaml b/test/integration/targets/ios_facts/tests/cli/invalid_subset.yaml index 4ee9f9bbc9..0cb0a7c0c0 100644 --- a/test/integration/targets/ios_facts/tests/cli/invalid_subset.yaml +++ b/test/integration/targets/ios_facts/tests/cli/invalid_subset.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/invalid_subset.yaml" +- debug: msg="START cli/invalid_subset.yaml on connection={{ ansible_connection }}" - name: test invalid subset (foobar) @@ -7,6 +7,7 @@ gather_subset: - "foobar" authorize: yes + become: yes register: result ignore_errors: true @@ -30,6 +31,7 @@ - "!hardware" - "hardware" authorize: yes + become: yes register: result ignore_errors: true @@ -45,4 +47,4 @@ -- debug: msg="END cli/invalid_subset.yaml" +- debug: msg="END cli/invalid_subset.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_facts/tests/cli/not_hardware.yaml b/test/integration/targets/ios_facts/tests/cli/not_hardware.yaml index b689805dfc..ba8e455c6a 100644 --- a/test/integration/targets/ios_facts/tests/cli/not_hardware.yaml +++ b/test/integration/targets/ios_facts/tests/cli/not_hardware.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/not_hardware_facts.yaml" +- debug: msg="START cli/not_hardware_facts.yaml on connection={{ ansible_connection }}" - name: test not hardware @@ -7,6 +7,7 @@ gather_subset: - "!hardware" authorize: yes + become: yes register: result - assert: @@ -27,4 +28,4 @@ # ... and not present - "result.ansible_facts.ansible_net_filesystems is not defined" -- debug: msg="END cli/not_hardware_facts.yaml" +- debug: msg="END cli/not_hardware_facts.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_interface/tasks/cli.yaml b/test/integration/targets/ios_interface/tasks/cli.yaml index d675462dd0..a6f7ae0351 100644 --- a/test/integration/targets/ios_interface/tasks/cli.yaml +++ b/test/integration/targets/ios_interface/tasks/cli.yaml @@ -4,12 +4,19 @@ paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" register: test_cases + delegate_to: localhost - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_interface/tests/cli/basic.yaml b/test/integration/targets/ios_interface/tests/cli/basic.yaml index 29a38d78fb..80ffba2407 100644 --- a/test/integration/targets/ios_interface/tests/cli/basic.yaml +++ b/test/integration/targets/ios_interface/tests/cli/basic.yaml @@ -1,10 +1,11 @@ --- -- debug: msg="START ios_interface cli/basic.yaml" +- debug: msg="START ios_interface cli/basic.yaml on connection={{ ansible_connection }}" - name: Run show version ios_command: commands: show version authorize: yes + become: yes register: show_version_result - block: @@ -23,6 +24,7 @@ - no negotiation auto parents: int GigabitEthernet2 authorize: yes + become: yes - name: Set test interface 2 to GigabitEthernet3 as we are on Cisco IOS-XE set_fact: test_interface2=GigabitEthernet3 @@ -32,6 +34,7 @@ - no negotiation auto parents: int GigabitEthernet3 authorize: yes + become: yes when: "'Cisco IOS-XE' in show_version_result.stdout[0]" - name: Configure interface (setup) @@ -42,6 +45,7 @@ mtu: 1800 state: present authorize: yes + become: yes register: result - name: Configure interface @@ -50,6 +54,7 @@ description: test-interface-initial state: present authorize: yes + become: yes register: result - assert: @@ -64,6 +69,7 @@ description: test-interface-initial state: present authorize: yes + become: yes register: result - assert: @@ -77,6 +83,7 @@ mtu: 2000 state: present authorize: yes + become: yes register: result - assert: @@ -93,6 +100,7 @@ mtu: 1800 state: present authorize: yes + become: yes register: result - assert: @@ -107,6 +115,7 @@ name: "{{ test_interface }}" enabled: False authorize: yes + become: yes register: result - assert: @@ -120,6 +129,7 @@ name: "{{ test_interface }}" enabled: True authorize: yes + become: yes register: result - assert: @@ -136,6 +146,7 @@ mtu: 1800 state: present authorize: yes + become: yes register: result - name: Add interface aggregate @@ -146,6 +157,7 @@ speed: 1000 state: present authorize: yes + become: yes register: result - assert: @@ -165,6 +177,7 @@ speed: 1000 state: present authorize: yes + become: yes register: result - assert: @@ -179,6 +192,7 @@ enabled: False state: present authorize: yes + become: yes register: result - assert: @@ -197,6 +211,7 @@ enabled: True state: present authorize: yes + become: yes register: result - assert: @@ -214,6 +229,7 @@ - name: Loopback10 state: absent authorize: yes + become: yes - name: Create loopback interface aggregate ios_interface: @@ -222,6 +238,7 @@ - name: Loopback10 state: present authorize: yes + become: yes register: result - assert: @@ -237,6 +254,7 @@ - name: Loopback10 state: absent authorize: yes + become: yes register: result - assert: @@ -252,10 +270,11 @@ - name: Loopback10 state: absent authorize: yes + become: yes register: result - assert: that: - 'result.changed == false' -- debug: msg="END ios_interface cli/basic.yaml" +- debug: msg="END ios_interface cli/basic.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_interface/tests/cli/intent.yaml b/test/integration/targets/ios_interface/tests/cli/intent.yaml index 8af87d1107..eb3620f2ee 100644 --- a/test/integration/targets/ios_interface/tests/cli/intent.yaml +++ b/test/integration/targets/ios_interface/tests/cli/intent.yaml @@ -1,10 +1,11 @@ --- -- debug: msg="START ios_interface cli/intent.yaml" +- debug: msg="START ios_interface cli/intent.yaml on connection={{ ansible_connection }}" - name: Run show version ios_command: commands: show version authorize: yes + become: yes register: show_version_result - name: Set test interface to GigabitEthernet0/2 if we are on Cisco IOS @@ -23,6 +24,7 @@ tx_rate: ge(0) rx_rate: ge(0) authorize: yes + become: yes register: result - assert: @@ -36,6 +38,7 @@ tx_rate: gt(0) rx_rate: lt(0) authorize: yes + become: yes ignore_errors: yes register: result @@ -52,6 +55,7 @@ enabled: False state: down authorize: yes + become: yes register: result - assert: @@ -64,6 +68,7 @@ enabled: False authorize: yes state: up + become: yes ignore_errors: yes register: result @@ -77,6 +82,7 @@ commands: - show lldp neighbors authorize: yes + become: yes register: show_lldp_neighbors_result - block: @@ -87,6 +93,7 @@ - port: eth0 host: netdev authorize: yes + become: yes register: result - assert: @@ -100,6 +107,7 @@ - port: dummy_port host: dummy_host authorize: yes + become: yes ignore_errors: yes register: result @@ -117,6 +125,7 @@ enabled: True state: up authorize: yes + become: yes ignore_errors: yes register: result @@ -133,6 +142,7 @@ - port: eth0 host: netdev authorize: yes + become: yes ignore_errors: yes register: result @@ -150,6 +160,7 @@ - port: dummy_port host: dummy_host authorize: yes + become: yes ignore_errors: yes register: result diff --git a/test/integration/targets/ios_logging/tasks/cli.yaml b/test/integration/targets/ios_logging/tasks/cli.yaml index d675462dd0..a6f7ae0351 100644 --- a/test/integration/targets/ios_logging/tasks/cli.yaml +++ b/test/integration/targets/ios_logging/tasks/cli.yaml @@ -4,12 +4,19 @@ paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" register: test_cases + delegate_to: localhost - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_logging/tests/cli/basic.yaml b/test/integration/targets/ios_logging/tests/cli/basic.yaml index 4061b279ea..46f47765c1 100644 --- a/test/integration/targets/ios_logging/tests/cli/basic.yaml +++ b/test/integration/targets/ios_logging/tests/cli/basic.yaml @@ -6,6 +6,7 @@ name: 172.16.0.1 state: absent authorize: yes + become: yes - name: Remove console ios_logging: @@ -13,6 +14,7 @@ level: warnings state: absent authorize: yes + become: yes - name: Remove buffer ios_logging: @@ -20,6 +22,7 @@ size: 8000 authorize: yes state: absent + become: yes # start tests - name: Set up host logging @@ -29,6 +32,7 @@ facility: local7 state: present authorize: yes + become: yes register: result - assert: @@ -43,6 +47,7 @@ name: 172.16.0.1 state: present authorize: yes + become: yes register: result - assert: @@ -55,6 +60,7 @@ name: 172.16.0.1 state: absent authorize: yes + become: yes register: result - assert: @@ -68,6 +74,7 @@ name: 172.16.0.1 state: absent authorize: yes + become: yes register: result - assert: @@ -80,6 +87,7 @@ level: warnings state: present authorize: yes + become: yes register: result - assert: @@ -92,6 +100,7 @@ dest: buffered size: 8000 authorize: yes + become: yes register: result - assert: @@ -105,6 +114,7 @@ - { dest: console, level: notifications } - { dest: buffered, size: 9000 } authorize: yes + become: yes register: result - assert: @@ -120,6 +130,7 @@ - { dest: buffered, size: 9000 } state: absent authorize: yes + become: yes register: result - assert: diff --git a/test/integration/targets/ios_ping/tasks/cli.yaml b/test/integration/targets/ios_ping/tasks/cli.yaml index 46d86dd698..a6f7ae0351 100644 --- a/test/integration/targets/ios_ping/tasks/cli.yaml +++ b/test/integration/targets/ios_ping/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_ping/tests/cli/ping.yaml b/test/integration/targets/ios_ping/tests/cli/ping.yaml index 97b22f1330..5a8c1154cd 100644 --- a/test/integration/targets/ios_ping/tests/cli/ping.yaml +++ b/test/integration/targets/ios_ping/tests/cli/ping.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/ping.yaml" +- debug: msg="START cli/ping.yaml on connection={{ ansible_connection }}" - ios_command: commands: show version diff --git a/test/integration/targets/ios_static_route/tasks/cli.yaml b/test/integration/targets/ios_static_route/tasks/cli.yaml index d675462dd0..a6f7ae0351 100644 --- a/test/integration/targets/ios_static_route/tasks/cli.yaml +++ b/test/integration/targets/ios_static_route/tasks/cli.yaml @@ -4,12 +4,19 @@ paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" register: test_cases + delegate_to: localhost - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_static_route/tests/cli/basic.yaml b/test/integration/targets/ios_static_route/tests/cli/basic.yaml index 5de2c626f5..2472b6dde3 100644 --- a/test/integration/targets/ios_static_route/tests/cli/basic.yaml +++ b/test/integration/targets/ios_static_route/tests/cli/basic.yaml @@ -6,6 +6,7 @@ next_hop: 10.0.0.8 state: present authorize: yes + become: yes register: result - assert: @@ -20,6 +21,7 @@ next_hop: 10.0.0.8 state: present authorize: yes + become: yes register: result - assert: @@ -34,6 +36,7 @@ admin_distance: 2 state: present authorize: yes + become: yes register: result - assert: @@ -49,6 +52,7 @@ admin_distance: 2 state: present authorize: yes + become: yes register: result - assert: @@ -63,6 +67,7 @@ admin_distance: 2 state: absent authorize: yes + become: yes register: result - assert: @@ -78,6 +83,7 @@ admin_distance: 2 state: absent authorize: yes + become: yes register: result - assert: @@ -91,6 +97,7 @@ - { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8 } state: present authorize: yes + become: yes register: result - assert: @@ -106,6 +113,7 @@ - { prefix: 172.16.34.0, mask: 255.255.255.0, next_hop: 10.0.0.8 } state: present authorize: yes + become: yes register: result - assert: @@ -121,6 +129,7 @@ - { prefix: 172.16.34.0, mask: 255.255.255.0, next_hop: 10.0.0.8 } state: absent authorize: yes + become: yes register: result - assert: diff --git a/test/integration/targets/ios_system/tasks/cli.yaml b/test/integration/targets/ios_system/tasks/cli.yaml index 46d86dd698..a6f7ae0351 100644 --- a/test/integration/targets/ios_system/tasks/cli.yaml +++ b/test/integration/targets/ios_system/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_system/tests/cli/set_domain_list.yaml b/test/integration/targets/ios_system/tests/cli/set_domain_list.yaml index 2fabf6ebbb..329fdc5d78 100644 --- a/test/integration/targets/ios_system/tests/cli/set_domain_list.yaml +++ b/test/integration/targets/ios_system/tests/cli/set_domain_list.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/set_domain_search.yaml" +- debug: msg="START cli/set_domain_search.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -8,6 +8,7 @@ - no ip domain-list redhat.com match: none authorize: yes + become: yes - name: configure domain_search ios_system: @@ -15,6 +16,7 @@ - ansible.com - redhat.com authorize: yes + become: yes register: result - assert: @@ -29,6 +31,7 @@ - ansible.com - redhat.com authorize: yes + become: yes register: result - assert: @@ -40,6 +43,7 @@ domain_search: - ansible.com authorize: yes + become: yes register: result - assert: @@ -52,6 +56,7 @@ domain_search: - ansible.com authorize: yes + become: yes register: result - assert: @@ -64,6 +69,7 @@ - ansible.com - redhat.com authorize: yes + become: yes register: result - assert: @@ -77,6 +83,7 @@ - ansible.com - redhat.com authorize: yes + become: yes register: result - assert: @@ -89,6 +96,7 @@ - ansible.com - eng.ansible.com authorize: yes + become: yes register: result - assert: @@ -104,6 +112,7 @@ - ansible.com - eng.ansible.com authorize: yes + become: yes register: result - assert: @@ -118,5 +127,6 @@ - no ip domain-list eng.ansible.com match: none authorize: yes + become: yes -- debug: msg="END cli/set_domain_search.yaml" +- debug: msg="END cli/set_domain_search.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_system/tests/cli/set_domain_name.yaml b/test/integration/targets/ios_system/tests/cli/set_domain_name.yaml index 335ff81bb0..7b4e939afc 100644 --- a/test/integration/targets/ios_system/tests/cli/set_domain_name.yaml +++ b/test/integration/targets/ios_system/tests/cli/set_domain_name.yaml @@ -1,16 +1,18 @@ --- -- debug: msg="START cli/set_domain_name.yaml" +- debug: msg="START cli/set_domain_name.yaml on connection={{ ansible_connection }}" - name: setup ios_config: lines: no ip domain-name match: none authorize: yes + become: yes - name: configure domain_name ios_system: domain_name: eng.ansible.com authorize: yes + become: yes register: result - assert: @@ -21,6 +23,7 @@ ios_system: domain_name: eng.ansible.com authorize: yes + become: yes register: result - assert: @@ -32,5 +35,6 @@ lines: no ip domain-name match: none authorize: yes + become: yes -- debug: msg="END cli/set_domain_name.yaml" +- debug: msg="END cli/set_domain_name.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_system/tests/cli/set_hostname.yaml b/test/integration/targets/ios_system/tests/cli/set_hostname.yaml index 17975c831f..0fa4a017fd 100644 --- a/test/integration/targets/ios_system/tests/cli/set_hostname.yaml +++ b/test/integration/targets/ios_system/tests/cli/set_hostname.yaml @@ -1,16 +1,18 @@ --- -- debug: msg="START cli/set_hostname.yaml" +- debug: msg="START cli/set_hostname.yaml on connection={{ ansible_connection }}" - name: setup ios_config: lines: hostname switch match: none authorize: yes + become: yes - name: configure hostname ios_system: hostname: foo authorize: yes + become: yes register: result - assert: @@ -21,6 +23,7 @@ ios_system: hostname: foo authorize: yes + become: yes register: result - assert: @@ -32,5 +35,6 @@ lines: "hostname {{ inventory_hostname }}" match: none authorize: yes + become: yes -- debug: msg="END cli/set_hostname.yaml" +- debug: msg="END cli/set_hostname.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_system/tests/cli/set_lookup_source.yaml b/test/integration/targets/ios_system/tests/cli/set_lookup_source.yaml index 31d784125e..70edf7e11f 100644 --- a/test/integration/targets/ios_system/tests/cli/set_lookup_source.yaml +++ b/test/integration/targets/ios_system/tests/cli/set_lookup_source.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/set_lookup_source.yaml" +- debug: msg="START cli/set_lookup_source.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -8,11 +8,13 @@ - vrf definition ansible match: none authorize: yes + become: yes - name: configure lookup_source ios_system: lookup_source: Loopback888 authorize: yes + become: yes register: result - assert: @@ -24,6 +26,7 @@ ios_system: lookup_source: Loopback888 authorize: yes + become: yes register: result - assert: @@ -34,6 +37,7 @@ ios_system: lookup_enabled: False authorize: yes + become: yes register: result - assert: @@ -45,6 +49,7 @@ ios_system: lookup_enabled: True authorize: yes + become: yes register: result - assert: @@ -59,6 +64,7 @@ # vrf: ansible # authorize: yes # provider: "{{ cli }}" +# become: yes # register: result # #- assert: @@ -75,6 +81,7 @@ # vrf: ansible # authorize: yes # provider: "{{ cli }}" +# become: yes # register: result # #- assert: @@ -88,7 +95,8 @@ - no vrf definition ansible match: none authorize: yes + become: yes ignore_errors: yes # FIXME: Not sure why this is failing with msg": "no vrf definition ansible\r\n% IPv4 and IPv6 addresses from all interfaces in VRF ansible have been removed\r\nfoo(config)#", rc:1 -- debug: msg="END cli/set_lookup_source.yaml" +- debug: msg="END cli/set_lookup_source.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_system/tests/cli/set_name_servers.yaml b/test/integration/targets/ios_system/tests/cli/set_name_servers.yaml index 9f03d61a24..77c6e82f72 100644 --- a/test/integration/targets/ios_system/tests/cli/set_name_servers.yaml +++ b/test/integration/targets/ios_system/tests/cli/set_name_servers.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/set_name_servers.yaml" +- debug: msg="START cli/set_name_servers.yaml on connection={{ ansible_connection }}" - name: setup ios_config: @@ -7,6 +7,7 @@ - no ip name-server match: none authorize: yes + become: yes - name: configure name_servers ios_system: @@ -15,6 +16,7 @@ - 2.2.2.2 - 3.3.3.3 authorize: yes + become: yes register: result - assert: @@ -32,6 +34,7 @@ - 2.2.2.2 - 3.3.3.3 authorize: yes + become: yes register: result - assert: @@ -73,6 +76,7 @@ - 1.1.1.1 - 2.2.2.2 authorize: yes + become: yes register: result - assert: @@ -87,5 +91,6 @@ - no ip name-server match: none authorize: yes + become: yes -- debug: msg="END cli/set_name_servers.yaml" +- debug: msg="END cli/set_name_servers.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/ios_user/tasks/cli.yaml b/test/integration/targets/ios_user/tasks/cli.yaml index d675462dd0..a6f7ae0351 100644 --- a/test/integration/targets/ios_user/tasks/cli.yaml +++ b/test/integration/targets/ios_user/tasks/cli.yaml @@ -4,12 +4,19 @@ paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" register: test_cases + delegate_to: localhost - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_user/tests/cli/auth.yaml b/test/integration/targets/ios_user/tests/cli/auth.yaml index 27cf9245e7..0144c838eb 100644 --- a/test/integration/targets/ios_user/tests/cli/auth.yaml +++ b/test/integration/targets/ios_user/tests/cli/auth.yaml @@ -8,6 +8,7 @@ state: present authorize: yes configured_password: pass123 + become: yes - name: test login expect: @@ -34,6 +35,7 @@ name: auth_user state: absent authorize: yes + become: yes register: result - name: reset connection diff --git a/test/integration/targets/ios_user/tests/cli/basic.yaml b/test/integration/targets/ios_user/tests/cli/basic.yaml index 7891f9c2cc..ea1cbe5928 100644 --- a/test/integration/targets/ios_user/tests/cli/basic.yaml +++ b/test/integration/targets/ios_user/tests/cli/basic.yaml @@ -7,7 +7,7 @@ - name: ansibletest3 state: absent authorize: yes - register: result + become: yes - name: Create user (SetUp) ios_user: @@ -16,6 +16,7 @@ role: network-operator state: present authorize: yes + become: yes register: result - assert: @@ -31,6 +32,7 @@ authorize: yes state: present view: network-admin + become: yes register: result - assert: @@ -45,6 +47,7 @@ role: network-operator state: present authorize: yes + become: yes register: result - assert: @@ -60,6 +63,7 @@ authorize: yes state: present view: network-admin + become: yes register: result - assert: @@ -75,6 +79,7 @@ - name: ansibletest3 state: absent authorize: yes + become: yes register: result - assert: diff --git a/test/integration/targets/ios_vlan/tasks/cli.yaml b/test/integration/targets/ios_vlan/tasks/cli.yaml index 46d86dd698..a6f7ae0351 100644 --- a/test/integration/targets/ios_vlan/tasks/cli.yaml +++ b/test/integration/targets/ios_vlan/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_vlan/tests/cli/basic.yaml b/test/integration/targets/ios_vlan/tests/cli/basic.yaml index a9727c32af..9761a98c8a 100644 --- a/test/integration/targets/ios_vlan/tests/cli/basic.yaml +++ b/test/integration/targets/ios_vlan/tests/cli/basic.yaml @@ -6,6 +6,7 @@ # - no vlan 200 # - no vlan 300 # authorize: yes +# become: yes #- name: setup - remove switchport settings on interfaces used in test # ios_config: @@ -14,6 +15,7 @@ # - no switchport access vlan 100 # authorize: yes # parents: "{{ item }}" +# become: yes # with_items: # - interface GigabitEthernet0/1 # - interface GigabitEthernet0/2 @@ -23,6 +25,7 @@ # vlan_id: 100 # name: test-vlan # authorize: yes +# become: yes # register: result #- assert: @@ -33,6 +36,7 @@ #- name: create vlan(idempotence) # ios_vlan: *create +# become: yes # register: result #- assert: @@ -46,6 +50,7 @@ # - GigabitEthernet0/1 # - GigabitEthernet0/2 # authorize: yes +# become: yes # register: result #- assert: @@ -60,6 +65,7 @@ #- name: Add interfaces to vlan(idempotence) # ios_vlan: *interfaces +# become: yes # register: result #- assert: @@ -72,7 +78,8 @@ # interfaces: # - GigabitEthernet0/1 # authorize: yes -# register: result +# become: yes +# register: result #- assert: # that: @@ -84,6 +91,7 @@ #- name: Remove interface from vlan(idempotence) # ios_vlan: *single_int +# become: yes # register: result #- assert: @@ -95,6 +103,7 @@ # vlan_id: 100 # state: suspend # authorize: yes +# become: yes # register: result #- assert: @@ -108,6 +117,7 @@ # vlan_id: 100 # state: active # authorize: yes +# become: yes # register: result #- assert: @@ -121,6 +131,7 @@ # vlan_id: 100 # authorize: yes # state: absent +# become: yes # register: result #- assert: @@ -130,6 +141,7 @@ #- name: delete vlan(idempotence) # ios_vlan: *delete +# become: yes # register: result #- assert: @@ -142,6 +154,7 @@ # - { vlan_id: 200, name: vlan-200 } # - { vlan_id: 300, name: vlan-300 } # authorize: yes +# become: yes # register: result #- assert: @@ -154,6 +167,7 @@ #- name: create vlans using aggregate(idempotence) # ios_vlan: *create_aggregate +# become: yes # register: result #- assert: @@ -167,6 +181,7 @@ # - { vlan_id: 300, name: vlan-300 } # state: absent # authorize: yes +# become: yes # register: result #- assert: @@ -177,6 +192,7 @@ #- name: delete vlans using aggregate(idempotence) # ios_vlan: *delete_aggregate +# become: yes # register: result #- assert: @@ -190,6 +206,7 @@ # - no vlan 200 # - no vlan 300 # authorize: yes +# become: yes #- name: teardown(part2) # ios_config: @@ -198,6 +215,7 @@ # - no switchport access vlan 100 # authorize: yes # parents: "{{ item }}" +# become: yes # with_items: # - interface GigabitEthernet0/1 # - interface GigabitEthernet0/2 diff --git a/test/integration/targets/prepare_ios_tests/tasks/main.yml b/test/integration/targets/prepare_ios_tests/tasks/main.yml index 9a8672c1a2..d4b89ae4c9 100644 --- a/test/integration/targets/prepare_ios_tests/tasks/main.yml +++ b/test/integration/targets/prepare_ios_tests/tasks/main.yml @@ -3,7 +3,8 @@ - name: Ensure we have loopback 888 for testing ios_config: src: config.j2 - authorize: yes + connection: network_cli + become: yes # Some AWS hostnames can be longer than those allowed by the system we are testing # Truncate the hostname diff --git a/test/units/modules/network/ios/test_ios_user.py b/test/units/modules/network/ios/test_ios_user.py index ee185eb7db..d6f2dbf66e 100644 --- a/test/units/modules/network/ios/test_ios_user.py +++ b/test/units/modules/network/ios/test_ios_user.py @@ -58,7 +58,7 @@ class TestIosUserModule(TestIosModule): set_module_args(dict(name='ansible', state='absent')) result = self.execute_module(changed=True) cmd = json.loads( - '{"answer": "y", ' + + '{"answer": "y", "newline": false, ' + '"prompt": "This operation will remove all username related ' + 'configurations with same name", "command": "no username ansible"}' ) @@ -87,7 +87,7 @@ class TestIosUserModule(TestIosModule): set_module_args(dict(purge=True)) result = self.execute_module(changed=True) cmd = json.loads( - '{"answer": "y", ' + + '{"answer": "y", "newline": false, ' + '"prompt": "This operation will remove all username related ' + 'configurations with same name", "command": "no username ansible"}' )