私の目標は、ciscoスイッチでinterfcesをループオーバーして、アクセスVLANを確認してから、そのVLANを "12"に設定するか、それ以外の場合にそのままライブすることです。可能なループの結果+ whenステートメント
- name: change vlan if needed
ios_config:
lines: switchport access vlan 1234
parents: interface Fa0/{{item}}
when: item.stdout_lines == " switchport access vlan 12"
with_items: "{{ int_out.results }}"
しかし:私は結果「INT_OUT」とアクセスVLANを変更するには、以下のようにstatemant「とき」に使用をループしたい
- name: check vlan on some interfaces and save to int_out
ios_command:
commands: show run int Fa0/{{ item }} | incl switchport access vlan
provider: "{{ cli }}"
with_sequence: start=1 end=3 stride=1
register: int_out
:私は「INT_OUT」につながる保存することを行います比較できません:
TASK [change vlan when needed] *************************************************
skipping: [192.168.0.33] => (item={u'changed': False, '_ansible_no_log': False, u'stdout': [u' switchport access vlan 12'], '_ansible_item_result': True, 'item': u'1', 'invocation': {'module_name': u'ios_command', u'module_args': {u'authorize': False, u'username': u'admin', u'commands': [u'show run int Fa0/1 | incl switchport access vlan'], u'auth_pass': None, u'retries': 10, u'waitfor': None, u'interval': 1, u'host': u'192.168.0.33', u'ssh_keyfile': None, u'timeout': 10, u'provider': u"{'username': 'admin', 'host': '192.168.0.33', 'password': '********'}", u'password': u'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', u'port': 22}}, u'stdout_lines': [[u' switchport access vlan 12']]})
skipping: [192.168.0.33] => (item={u'changed': False, '_ansible_no_log': False, u'stdout': [u' switchport access vlan 12'], '_ansible_item_result': True, 'item': u'2', 'invocation': {'module_name': u'ios_command', u'module_args': {u'authorize': False, u'username': u'admin', u'commands': [u'show run int Fa0/2 | incl switchport access vlan'], u'auth_pass': None, u'retries': 10, u'waitfor': None, u'interval': 1, u'host': u'192.168.0.33', u'ssh_keyfile': None, u'timeout': 10, u'provider': u"{'username': 'admin', 'host': '192.168.0.33', 'password': '********'}", u'password': u'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', u'port': 22}}, u'stdout_lines': [[u' switchport access vlan 12']]})
skipping: [192.168.0.33] => (item={u'changed': False, '_ansible_no_log': False, u'stdout': [u' switchport access vlan 12'], '_ansible_item_result': True, 'item': u'3', 'invocation': {'module_name': u'ios_command', u'module_args': {u'authorize': False, u'username': u'admin', u'commands': [u'show run int Fa0/3 | incl switchport access vlan'], u'auth_pass': None, u'retries': 10, u'waitfor': None, u'interval': 1, u'host': u'192.168.0.33', u'ssh_keyfile': None, u'timeout': 10, u'provider': u"{'username': 'admin', 'host': '192.168.0.33', 'password': '********'}", u'password': u'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', u'port': 22}}, u'stdout_lines': [[u' switchport access vlan 12']]})
私が間違っているWAHT見るために「item.stdout_lines」の出力を確認した場合:
- debug: msg= "{{ item.stdout_lines }}"
with_items: "{{ int_out.results }}"
私はstdout_linesが、多くのだけではないの取得:
TASK [debug] *******************************************************************
ok: [192.168.0.33] => (item={u'changed': False, '_ansible_no_log': False, u'stdout': [u' switchport access vlan 12'], '_ansible_item_result': True, 'item': u'1', 'invocation': {'module_name': u'ios_command', u'module_args': {u'authorize': False, u'username': u'admin', u'commands': [u'show run int Fa0/1 | incl switchport access vlan'], u'auth_pass': None, u'retries': 10, u'waitfor': None, u'interval': 1, u'host': u'192.168.0.33', u'ssh_keyfile': None, u'timeout': 10, u'provider': u"{'username': 'admin', 'host': '192.168.0.33', 'password': '********'}", u'password': u'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', u'port': 22}}, u'stdout_lines': [[u' switchport access vlan 12']]}) => {
"item": {
"changed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": false,
"commands": [
"show run int Fa0/1 | incl switchport access vlan"
],
"host": "192.168.0.33",
"interval": 1,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 22,
"provider": "{'username': 'admin', 'host': '192.168.0.33', 'password': '********'}",
"retries": 10,
"ssh_keyfile": null,
"timeout": 10,
"username": "admin",
"waitfor": null
},
"module_name": "ios_command"
},
"item": "1",
"stdout": [
" switchport access vlan 12"
],
"stdout_lines": [
[
" switchport access vlan 12"
]
]
},
"msg": ""
}
ok: [192.168.0.33] => (item={u'changed': False, '_ansible_no_log': False, u'stdout': [u' switchport access vlan 12'], '_ansible_item_result': True, 'item': u'2', 'invocation': {'module_name': u'ios_command', u'module_args': {u'authorize': False, u'username': u'admin', u'commands': [u'show run int Fa0/2 | incl switchport access vlan'], u'auth_pass': None, u'retries': 10, u'waitfor': None, u'interval': 1, u'host': u'192.168.0.33', u'ssh_keyfile': None, u'timeout': 10, u'provider': u"{'username': 'admin', 'host': '192.168.0.33', 'password': '********'}", u'password': u'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', u'port': 22}}, u'stdout_lines': [[u' switchport access vlan 12']]}) => {
"item": {
"changed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": false,
"commands": [
"show run int Fa0/2 | incl switchport access vlan"
],
"host": "192.168.0.33",
"interval": 1,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 22,
"provider": "{'username': 'admin', 'host': '192.168.0.33', 'password': '********'}",
"retries": 10,
"ssh_keyfile": null,
"timeout": 10,
"username": "admin",
"waitfor": null
},
"module_name": "ios_command"
},
"item": "2",
"stdout": [
" switchport access vlan 12"
],
"stdout_lines": [
[
" switchport access vlan 12"
]
]
},
"msg": ""
}
ok: [192.168.0.33] => (item={u'changed': False, '_ansible_no_log': False, u'stdout': [u' switchport access vlan 12'], '_ansible_item_result': True, 'item': u'3', 'invocation': {'module_name': u'ios_command', u'module_args': {u'authorize': False, u'username': u'admin', u'commands': [u'show run int Fa0/3 | incl switchport access vlan'], u'auth_pass': None, u'retries': 10, u'waitfor': None, u'interval': 1, u'host': u'192.168.0.33', u'ssh_keyfile': None, u'timeout': 10, u'provider': u"{'username': 'admin', 'host': '192.168.0.33', 'password': '********'}", u'password': u'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', u'port': 22}}, u'stdout_lines': [[u' switchport access vlan 12']]}) => {
"item": {
"changed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": false,
"commands": [
"show run int Fa0/3 | incl switchport access vlan"
],
"host": "192.168.0.33",
"interval": 1,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 22,
"provider": "{'username': 'admin', 'host': '192.168.0.33', 'password': '********'}",
"retries": 10,
"ssh_keyfile": null,
"timeout": 10,
"username": "admin",
"waitfor": null
},
"module_name": "ios_command"
},
"item": "3",
"stdout": [
" switchport access vlan 12"
],
"stdout_lines": [
[
" switchport access vlan 12"
]
]
},
"msg": ""
}
しかし、私のようなコードを実行しますこの:
- debug: msg="{{int_out.results[1].stdout}}"
私は、このような応答を取得:
TASK [debug] *******************************************************************
ok: [192.168.0.33] => {
"msg": [
" switchport access vlan 12"
]
}
どのようなアイデアwron'gと私はどのように私の目標を達成することができますか?
素晴らしい。これだよ! –
ご協力いただきありがとうございます。 –