{"action":"created","issue":{"url":"https://api.github.com/repos/ansible-network/network-engine/issues/151","repository_url":"https://api.github.com/repos/ansible-network/network-engine","labels_url":"https://api.github.com/repos/ansible-network/network-engine/issues/151/labels{/name}","comments_url":"https://api.github.com/repos/ansible-network/network-engine/issues/151/comments","events_url":"https://api.github.com/repos/ansible-network/network-engine/issues/151/events","html_url":"https://github.com/ansible-network/network-engine/issues/151","id":366536940,"node_id":"MDU6SXNzdWUzNjY1MzY5NDA=","number":151,"title":"JSON templating incorrectly changes the value to type int","user":{"login":"lancewood1","id":26907283,"node_id":"MDQ6VXNlcjI2OTA3Mjgz","avatar_url":"https://avatars3.githubusercontent.com/u/26907283?v=4","gravatar_id":"","url":"https://api.github.com/users/lancewood1","html_url":"https://github.com/lancewood1","followers_url":"https://api.github.com/users/lancewood1/followers","following_url":"https://api.github.com/users/lancewood1/following{/other_user}","gists_url":"https://api.github.com/users/lancewood1/gists{/gist_id}","starred_url":"https://api.github.com/users/lancewood1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lancewood1/subscriptions","organizations_url":"https://api.github.com/users/lancewood1/orgs","repos_url":"https://api.github.com/users/lancewood1/repos","events_url":"https://api.github.com/users/lancewood1/events{/privacy}","received_events_url":"https://api.github.com/users/lancewood1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-03T21:28:44Z","updated_at":"2018-10-04T17:12:02Z","closed_at":null,"author_association":"NONE","body":"# ISSUE TYPE\r\n\r\n- Bug Report\r\n\r\n# SUMMARY\r\n\r\nThe `_coerce_to_native` function in \r\n`network-engine/lib/network_engine/plugins/template/__init__.py` \r\nincorrectly casts values to type integer.\r\n\r\n\r\nAny string value that looks like an integer is turned into an integer which causes issues.  Many network constructs should not be converted from type string.  For example, an ip prefix-list defined on a Cisco device could have a name similar to \"0012345678\" however once the that value goes through this process the prefix-list name is change to 12345678 of type integer.\r\n\r\nThe line `value = int(value)` is changing the variable type of objects that should be strings.\r\n\r\n```\r\n    def _coerce_to_native(self, value):\r\n        if not isinstance(value, bool):\r\n            try:\r\n                value = int(value)\r\n            except Exception:\r\n                if value is None or len(value) == 0:\r\n                    return None\r\n                pass\r\n        return value\r\n```\r\n# STEPS TO REPRODUCE\r\n\r\n```\r\ntext_parser:\r\n  file: \"ios_prefix_list_parser.yml\"\r\n  content: \"{{ prefix_list_output.stdout[0] }}\"\r\n```\r\n\r\n\r\n# EXPECTED RESULTS\r\nprefix_list[\"0012345678\"] is defined\r\n\r\n# ACTUAL RESULTS\r\nprefix_list[12345678] is defined\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ansible-network/network-engine/issues/comments/427098062","html_url":"https://github.com/ansible-network/network-engine/issues/151#issuecomment-427098062","issue_url":"https://api.github.com/repos/ansible-network/network-engine/issues/151","id":427098062,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNzA5ODA2Mg==","user":{"login":"lancewood1","id":26907283,"node_id":"MDQ6VXNlcjI2OTA3Mjgz","avatar_url":"https://avatars3.githubusercontent.com/u/26907283?v=4","gravatar_id":"","url":"https://api.github.com/users/lancewood1","html_url":"https://github.com/lancewood1","followers_url":"https://api.github.com/users/lancewood1/followers","following_url":"https://api.github.com/users/lancewood1/following{/other_user}","gists_url":"https://api.github.com/users/lancewood1/gists{/gist_id}","starred_url":"https://api.github.com/users/lancewood1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lancewood1/subscriptions","organizations_url":"https://api.github.com/users/lancewood1/orgs","repos_url":"https://api.github.com/users/lancewood1/repos","events_url":"https://api.github.com/users/lancewood1/events{/privacy}","received_events_url":"https://api.github.com/users/lancewood1/received_events","type":"User","site_admin":false},"created_at":"2018-10-04T17:12:02Z","updated_at":"2018-10-04T17:12:02Z","author_association":"NONE","body":"This is the parser template, it is available as\r\n        cisco_ios/parser_templates/config/show_ip_prefix_list.yaml\r\n\r\n```\r\n---\r\n- name: match sections\r\n  pattern_match:\r\n    regex: \"^ip\"\r\n    match_all: yes\r\n    match_greedy: yes\r\n  register: context\r\n\r\n- name: match prefix values\r\n  pattern_group:\r\n    - name: match name\r\n      pattern_match:\r\n        regex: \"ip prefix-list (?P<acl_name>.+): (\\\\d+) entries\"\r\n        content: \"{{ item }}\"\r\n      register: name\r\n\r\n    - name: match entries\r\n      pattern_match:\r\n        regex: \"seq (\\\\d+) (permit|deny) (\\\\S+)(?: (le|ge) (\\\\d+))*\"\r\n        content: \"{{ item }}\"\r\n        match_all: yes\r\n      register: entry\r\n  loop: \"{{ context }}\"\r\n  register: entries\r\n\r\n- name: template entries\r\n  json_template:\r\n    template:\r\n      - key: name\r\n        value: \"{{ item.name.acl_name }}\"\r\n      - key: entries\r\n        elements:\r\n          - key: sequence\r\n            value: \"{{ it.matches.0 }}\"\r\n          - key: action\r\n            value: \"{{ it.matches.1 }}\"\r\n          - key: prefix\r\n            value: \"{{ it.matches.2 }}\"\r\n          - key: operator\r\n            value: \"{{ it.matches.4 }}\"\r\n          - key: length\r\n            value: \"{{ it.matches.5 }}\"\r\n        repeat_for: \"{{ item.entry }}\"\r\n        repeat_var: it\r\n  register: prefix_list_list\r\n  export: yes\r\n  loop: \"{{ entries }}\"\r\n\r\n- name: template entries\r\n  json_template:\r\n    template:\r\n      - key: \"{{ item.name.acl_name }}\"\r\n        object:\r\n          - key: entries\r\n            elements:\r\n              - key: sequence\r\n                value: \"{{ it.matches.0 }}\"\r\n              - key: action\r\n                value: \"{{ it.matches.1 }}\"\r\n              - key: prefix\r\n                value: \"{{ it.matches.2 }}\"\r\n              - key: operator\r\n                value: \"{{ it.matches.3 }}\"\r\n              - key: length\r\n                value: \"{{ it.matches.4 }}\"\r\n            repeat_for: \"{{ item.entry }}\"\r\n            repeat_var: it\r\n  loop: \"{{ entries }}\"\r\n  export: yes\r\n  export_as: dict\r\n  extend: cisco_ios.config\r\n  register: prefix_list_dict\r\n\r\n- name: template acl and prefix\r\n  json_template:\r\n    template:\r\n      - key: acl\r\n        elements:\r\n          - key: acl_name\r\n            value: \"{{ item.name.acl_name }}\"\r\n          - key: prefix\r\n            value: \"{{ it.matches.2 }}\"\r\n        repeat_for: \"{{ item.entry }}\"\r\n        repeat_var: it\r\n  register: prefix_list_basic\r\n  export: yes\r\n  loop: \"{{ entries }}\"\r\n```\r\n\r\nThe prefix list output variable contains the following:\r\n```\r\nip prefix-list 0012345678: 1 entries\r\n  seq 10 permit 1.2.3.4/24 le 32\r\nip prefix-list 9876543210: 1 entries\r\n  seq 10 permit 2.4.6.8/24 le 32\r\n```\r\n"}}
{"actor":{"display_login":"lancewood1"}}