{"id":42422,"date":"2023-07-04T01:46:00","date_gmt":"2023-07-23T15:12:27","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/"},"modified":"2024-04-30T11:52:07","modified_gmt":"2024-04-30T03:52:07","slug":"%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/","title":{"rendered":"\u4f7f\u7528Ansible\u548cJinja\u4eceCSV\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6"},"content":{"rendered":"<h1>\u9996\u5148<\/h1>\n<p>\u6211\u4e4b\u524d\u7528Ansible\u521b\u5efa\u4e86\u4e00\u4e2a\u53ef\u4ee5\u83b7\u53d6\u65e5\u5fd7\u7684playbook\u3002<br \/>\n\u53ea\u9700\u66f4\u65b0playbook\u672c\u8eab\u7684\u76ee\u5f55\u4fe1\u606f\u548c\u60f3\u8981\u83b7\u53d6\u7684\u547d\u4ee4\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7SSH\u8fde\u63a5\u5230\u76ee\u6807\u4e3b\u673a\u5e76\u83b7\u53d6\u65e5\u5fd7\u3002<br \/>\n\u5728\u5b9e\u9645\u9a8c\u8bc1\u4e2d\uff0c\u73af\u5883\u53ef\u80fd\u4f1a\u7ecf\u5e38\u66f4\u6539\u3002<br \/>\n\u5373\u4f7f\u6709\u4eba\u4e0d\u719f\u6089Ansible\u6765\u64cd\u4f5c\uff0c\u4e5f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u80fd\u591f\u751f\u6210\u76ee\u6807\u4e3b\u673a\u65e5\u5fd7\u83b7\u53d6\u7684 inventory \u6587\u4ef6\uff0c\u53ea\u9700\u66f4\u65b0csv\u6587\u4ef6\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u3002<br \/>\n\u5177\u4f53\u6765\u8bf4\uff0c\u6211\u60f3\u8981\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u9a8c\u8bc1\u8bbe\u5907\u767b\u5f55\u4fe1\u606f\u7684csv\u6587\u4ef6\u548c\u4e00\u4e2ajinja\u6a21\u677f\u6587\u4ef6\u3002<br \/>\n\u901a\u8fc7\u4f7f\u7528Ansible\u7684template\u6a21\u5757\uff0c\u6211\u5c06\u521b\u5efa\u6700\u7ec8\u7684inventory\u6587\u4ef6\u3002<\/p>\n<h1>\u603b\u7ed3<\/h1>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">jinja2\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u5229\u7528\u3057\u3066\u30a4\u30f3\u30d9\u30f3\u30c8\u30ea\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u30a4\u30f3\u30d7\u30c3\u30c8\u306fcsv\u30d5\u30a1\u30a4\u30eb\u306e\u307f<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u30a2\u30a6\u30c8\u30d7\u30c3\u30c8\u306f\u30ed\u30b0\u53d6\u5f97\u7528\u306e\u30a4\u30f3\u30d9\u30f3\u30c8\u30ea\u30d5\u30a1\u30a4\u30eb<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u30a4\u30f3\u30d9\u30f3\u30c8\u30ea\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u306b\u8a18\u8f09\u3059\u308b\u3082\u306e<\/ul>\n<\/li>\n<\/ul>\n<p>\u30db\u30b9\u30c8\u3078\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u305f\u3081\u306e\u60c5\u5831<\/p>\n<p>\u30b0\u30eb\u30fc\u30d7<br \/>\n\u30db\u30b9\u30c8\u306eIP\u30a2\u30c9\u30ec\u30b9<br \/>\nSSH\u30e6\u30fc\u30b6\u30fc<br \/>\nSSH\u30d1\u30b9\u30ef\u30fc\u30c9<\/p>\n<p>\u53d6\u5f97\u3057\u305f\u3044\u30b3\u30de\u30f3\u30c9\u3092\u8a18\u8f09\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u5909\u6570<\/p>\n<p>show\u30b3\u30de\u30f3\u30c9<br \/>\nroute\u30b3\u30de\u30f3\u30c9<\/p>\n<p>Ansible\u306etemplate\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30d7\u30ec\u30a4\u30d6\u30c3\u30af\u5185\u306e\u30bf\u30b9\u30af\u306b\u8a18\u8f09\u3057\u3066\u3001\u30a4\u30f3\u30d9\u30f3\u30c8\u30ea\u30d5\u30a1\u30a4\u30eb\u3092\u751f\u6210<\/p>\n<p>\u8fd9\u6b21\u7684\u521b\u5efa\u4e2d\u5305\u542b\u4e86playbook\uff0c\u4f46\u662f\u4e0b\u6b21\u4ee5\u53ca\u4ee5\u540e\u53ea\u9700\u8981\u66f4\u65b0csv\u6587\u4ef6\uff0c\u5e76\u4e14\u901a\u8fc7\u521b\u5efa\u7684playbook\u6765\u5b9e\u73b0\u66f4\u65b0\u5e93\u5b58\u6587\u4ef6\u7684\u76ee\u7684\u3002<\/p>\n<h1>Jinja\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>Jinja\u662fPython\u7684\u6a21\u677f\u5f15\u64ce\uff0c\u5b83\u6839\u636e\u7ed9\u5b9a\u7684\u8f93\u5165\u6570\u636e\u548c\u6a21\u677f\u751f\u6210\u65b0\u7684\u6570\u636e\u3002\u53ef\u4ee5\u7528\u5b83\u751f\u6210\u5177\u6709\u53ef\u53d8\u503c\u7684\u52a8\u6001\u6e05\u5355\u6587\u4ef6\u6216\u751f\u6210\u7f51\u7edc\u8bbe\u5907\u7684\u914d\u7f6e\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d4ca937434c4406cbb633\/7-0.jpeg\" alt=\"\u30c6\u30f3\u30d5\u309a\u30ec\u30fc\u30c8.002.jpeg\" \/><\/div>\n<p>\u5728\u4e2d\u56fd\u4eba\u7fa4\u4e2d\uff0c\u4ee5\u4e0b\u662f\u5bf9\u4e0a\u8ff0\u5185\u5bb9\u7684\u672c\u571f\u5316\u8868\u8fbe\u65b9\u5f0f\uff1a<\/p>\n<p>\u9700\u8981\u81ea\u5df1\u5236\u4f5c\u6a21\u677f\u672c\u8eab\uff0c\u5e76\u521b\u5efa\u7528\u4e8e\u4f7f\u7528\u8be5\u6a21\u677f\u6587\u4ef6\u7684playbook\u3002<br \/>\n\u4f46\u662f\uff0c\u4e00\u65e6\u6839\u636e\u8f93\u5165\u6570\u636e\u521b\u5efa\u4e86\u9002\u5408\u7684\u6a21\u677f\u6587\u4ef6\uff0c\u4eca\u540e\u53ea\u9700\u8981\u66f4\u65b0CSV\u6587\u4ef6\u5373\u53ef\u751f\u6210\u7edf\u4e00\u63cf\u8ff0\u7684\u6e05\u5355\u6587\u4ef6\u3002<br \/>\nAnsible\u63d0\u4f9b\u4e86\u7528\u4e8e\u5229\u7528Jinja\u7684template\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528\u8be5\u6a21\u5757\u6765\u751f\u6210\u6587\u4ef6\u3002<\/p>\n<h1>\u751f\u6210\u7684\u6587\u4ef6\uff08\u5e93\u5b58\u6587\u4ef6\uff09<\/h1>\n<p>\u4e3a\u4e86\u66f4\u597d\u5730\u4e86\u89e3\u53ef\u4ee5\u521b\u5efa\u54ea\u4e9b\u6587\u4ef6\uff0c\u5728\u6b64\u5148\u8d34\u4e0a\u521b\u5efa\u7ed3\u679c\u7684\u6587\u4ef6\u3002\u6211\u8fd8\u65e0\u6cd5\u5f88\u597d\u5730\u5904\u7406\u7a7a\u884c\u7684\u95ee\u9898\u3002<\/p>\n<pre class=\"post-pre\"><code>[ios:children] # os\u7a2e\u5225\u3067\u30b0\u30eb\u30fc\u30d7\u3092\u4f5c\u308a\u3001\u5b50\u30b0\u30eb\u30fc\u30d7\u304c\u3042\u308c\u3070os\u7a2e\u5225\u306e\u914d\u4e0b\u306b\r\nl2\r\ndist\r\ninternet\r\n\r\n\r\n\r\n[l2] # \u5b50(\u306a\u3051\u308c\u3070\u89aa)\u30b0\u30eb\u30fc\u30d7\u306b\u30db\u30b9\u30c8\u306e\u30ed\u30b0\u30a4\u30f3\u60c5\u5831\u3092\u8a18\u8f09\u3002SSH\u63a5\u7d9a\u524d\u63d0\u3002\r\nedge-sw01 ansible_host=10.10.20.172 ansible_ssh_user=cisco ansible_ssh_pass=cisco\r\n[dist]\r\ndist-rtr01 ansible_host=10.10.20.175 ansible_ssh_user=cisco ansible_ssh_pass=cisco\r\ndist-rtr02 ansible_host=10.10.20.176 ansible_ssh_user=cisco ansible_ssh_pass=cisco\r\n[internet]\r\ninternet-rtr01 ansible_host=10.10.20.181 ansible_ssh_user=cisco ansible_ssh_pass=cisco\r\n\r\n[iosxr] # \u5b50\u30b0\u30eb\u30fc\u30d7\u304c\u306a\u3044\u30d1\u30bf\u30fc\u30f3\r\ncore-rtr01 ansible_host=10.10.20.173 ansible_ssh_user=cisco ansible_ssh_pass=cisco\r\ncore-rtr02 ansible_host=10.10.20.174 ansible_ssh_user=cisco ansible_ssh_pass=cisco\r\n\r\n[nxos]\r\ndist_sw01 ansible_host=10.10.20.178 ansible_ssh_user=cisco ansible_ssh_pass=cisco\r\ndist_sw02 ansible_host=10.10.20.179 ansible_ssh_user=cisco ansible_ssh_pass=cisco\r\n\r\n[all:vars]\u3000# \u3053\u308c\u306f\u74b0\u5883\u306b\u3088\u3089\u306a\u3044\u306e\u3067\u3001\u56fa\u5b9a\r\nansible_connection=network_cli\r\n\r\n[ios:vars] # \u89aa\u3001\u5b50\u30b0\u30eb\u30fc\u30d7\u3054\u3068\u306b\u8a18\u8f09\u3002\u89aa\u306fos\u7a2e\u5225\u306e\u5b9a\u7fa9\u304c\u30de\u30b9\u30c8\r\nansible_network_os=ios\r\n\r\n[l2:vars] # \u5b50\u30b0\u30eb\u30fc\u30d7\u304c\u3042\u308b\u5834\u5408\u306f\u5b50\u30b0\u30eb\u30fc\u30d7\u306e\u5909\u6570\u306b\u30b3\u30de\u30f3\u30c9\u8a18\u8f09\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5b9a\u7fa9\r\ncommands_show=l2_show.txt\r\ncommands_route=l2_route.txt\r\n\r\n[dist:vars]\r\ncommands_show=dist_show.txt\r\ncommands_route=dist_route.txt\r\n\r\n\r\n[internet:vars]\r\ncommands_show=internet_show.txt\r\ncommands_route=internet_route.txt\r\n\r\n\r\n[iosxr:vars]# \u5b50\u30b0\u30eb\u30fc\u30d7\u304c\u306a\u3044\u5834\u5408\u306f\u89aa\u30b0\u30eb\u30fc\u30d7\u306e\u5909\u6570\u306bos\u7a2e\u5225\u3068\u30b3\u30de\u30f3\u30c9\u8a18\u8f09\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5b9a\u7fa9\r\nansible_network_os=iosxr\r\ncommands_show=iosxr_show.txt\r\ncommands_route=iosxr_route.txt\r\n\r\n[nxos:vars]\r\nansible_network_os=nxos\r\ncommands_show=nxos_show.txt\r\ncommands_route=nxos_route.txt\r\n\r\n<\/code><\/pre>\n<h1>\u811a\u672c<\/h1>\n<h2>1. \u73a9\u6cd5\u624b\u518c<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u7528\u4e8e\u4f7f\u7528\u6a21\u677f\u7684\u64cd\u4f5c\u624b\u518c\u3002<\/p>\n<pre class=\"post-pre\"><code>---\r\n- hosts: localhost\r\n  gather_facts: no\r\n  connection: local\r\n\r\n  vars:\r\n    template: templates\/inventory.j2          # \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u6307\u5b9a\r\n    host_list: hosts_list.csv                 # \u30a4\u30f3\u30d7\u30c3\u30c8\u30c7\u30fc\u30bf\u3067\u3042\u308bcsv\u30d5\u30a1\u30a4\u30eb\u306e\u6307\u5b9a\r\n\r\n  tasks:\r\n    - name: read inventory csv\r\n      read_csv:                               # read_csv\u30e2\u30b8\u30e5\u30fc\u30eb\u3067csv\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\r\n        path: \"{{ host_list }}\"\r\n      run_once: yes\r\n      register: inventory_requests            # \u8aad\u307f\u8fbc\u3093\u3060\u7d50\u679c\u3092\u30ec\u30b8\u30b9\u30bf\u30fc\u306b\u683c\u7d0d\r\n\r\n    - name: display\r\n      debug:\r\n        msg: \"{{ inventory_requests.list }}\"  # \u8aad\u307f\u8fbc\u3093\u3060\u30c7\u30fc\u30bf\u306f\u30ea\u30b9\u30c8\r\n      run_once: yes\r\n\r\n    - name: set command requests\r\n      set_fact:\r\n        lists: \"{{ inventory_requests.list }}\" # \u4f7f\u7528\u3059\u308b\u30ea\u30b9\u30c8\u90e8\u5206\u306e\u307f\u3092\u5909\u6570\u306b\u683c\u7d0d\r\n      run_once: yes\r\n\r\n    - name: create inventory\r\n      template:                                # \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u3066jinja\u3092\u5229\u7528\r\n        src: \"{{ template }}\"                  # \u5229\u7528\u3059\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u6307\u5b9a\r\n        dest: \"dynamic_inventory.ini\"          # \u751f\u6210\u3055\u308c\u308b\u30d5\u30a1\u30a4\u30eb\u540d\r\n        lstrip_blocks: yes                     # \u5148\u982d\u306e\u30b9\u30da\u30fc\u30b9\u9664\u53bb\r\n<\/code><\/pre>\n<h2>2. csv \u6587\u4ef6<\/h2>\n<p>\u8fd9\u662f\u7528\u4f5c\u8f93\u5165\u6570\u636e\u7684CSV\u6587\u4ef6\u3002<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">&#8220;os&#8221;\u306fios,iosxr,nxos\u306e\u307f<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">&#8220;os&#8221;\u304c\u89aa\u30b0\u30eb\u30fc\u30d7\u306b\u306a\u308a\u3001&#8221;group&#8221;\u304c\u3042\u308c\u3070\u5b50\u30b0\u30eb\u30fc\u30d7\u3068\u3057\u3066\u8a8d\u8b58<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u201dos\u201d\u3001\u201dgroup\u201d\u306f\u4e26\u3073\u66ff\u3048\u3089\u308c\u3066\u3044\u308b\u524d\u63d0<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\u4f8b\u306b\u3088\u3063\u3066DEVNET sandbox\u306eCisco Modeling Labs\u306eMulti Platform Network\u306e\u30e9\u30dc\u306e\u60c5\u5831<\/ul>\n<div>\n<div class=\"post-table\">os<br \/>\n\uff08\u89aa\u30b0\u30eb\u30fc\u30d7\uff09group<br \/>\n(\u5b50\u30b0\u30eb\u30fc\u30d7)hostUsernamePasswordipiosl2edge-sw01ciscocisco10.10.20.172iosdistdist-rtr01ciscocisco10.10.20.175iosdistdist-rtr02ciscocisco10.10.20.176iosinternetinternet-rtr01ciscocisco10.10.20.181nxos<br \/>\ndist_sw01ciscocisco10.10.20.178nxos<br \/>\ndist_sw02ciscocisco10.10.20.179iosxr<br \/>\ncore-rtr01ciscocisco10.10.20.173iosxr<br \/>\ncore-rtr02ciscocisco10.10.20.174<\/div>\n<\/div>\n<pre class=\"post-pre\"><code>os,group,host,Username,Password,ip\r\nios,l2,edge-sw01,cisco,cisco,10.10.20.172\r\nios,dist,dist-rtr01,cisco,cisco,10.10.20.175\r\nios,dist,dist-rtr02,cisco,cisco,10.10.20.176\r\nios,internet,internet-rtr01,cisco,cisco,10.10.20.181\r\nnxos,,dist_sw01,cisco,cisco,10.10.20.178\r\nnxos,,dist_sw02,cisco,cisco,10.10.20.179\r\niosxr,,core-rtr01,cisco,cisco,10.10.20.173\r\niosxr,,core-rtr02,cisco,cisco,10.10.20.174\r\n\r\n<\/code><\/pre>\n<h2>3. \u6a21\u677f\u6587\u4ef6<\/h2>\n<p>\u975e\u5e38\u957f\u3002\u53ea\u8003\u8651\u4e86iOS\u3001iOS XR\u548cNX-OS\u8fd9\u4e09\u79cd\u3002\u201c\u57fa\u672c\u4e0a\u5206\u522b\u5217\u51fa\u4e86\u8fd9\u4e09\u79cd\u201d\uff0c\u6240\u4ee5\u53d8\u5f97\u5f88\u957f\u3002\u4f46\u8fd8\u662f\u5e0c\u671b\u80fd\u66f4\u7b80\u6d01\u5730\u5199\u3002<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">jinja2\u69cb\u6587<\/ul>\n<\/li>\n<\/ul>\n<p>\u30b3\u30e1\u30f3\u30c8 {# &#8230; #}<br \/>\n\u5236\u5fa1\u69cb\u6587 {% &#8230;%}<br \/>\n\u5909\u6570 {{ &#8230; }}<br \/>\n\u5909\u6570\u3092\u4f7f\u7528\u3057\u306a\u3051\u308c\u3070\u30d9\u30bf\u66f8\u304d<br \/>\n\u7a7a\u884c\u3001\u6539\u884c\u306e\u5236\u5fa1\u306b\u306fWhitespace Control<\/p>\n<pre class=\"post-pre\"><code>{# create variable for parent-children relations #}\r\n{# for ios #}\r\n{% set ns = namespace(str='') %}                    # for\u5206\u306e\u4e2d\u3067\u306f\u5909\u6570\u304cif\u6587\u5916\u3067\u5229\u7528\u3067\u304d\u306a\u3044\u305f\u3081for\u6587\u5916\u3067\u5ba3\u8a00\r\n{% for item in lists %}\r\n    {% if item.os == 'ios' %}\r\n        {% if item.group != '' %}\r\n            {% if ns.str == '' -%}\r\n                [ios:children]\r\n                {% set ns.str = item.group -%}      # if\u6587\u5916\u3067\u3082\u5909\u6570\u304c\u6709\u52b9\u306b\u306a\u308b\u3088\u3046\u306bnamespace\u3092\u5229\u7528\r\n                {{ item.group }}\r\n            {% else %}\r\n                {% if ns.str != item.group -%}\r\n                {{ item.group }}\r\n                {% set ns.str = item.group %}\r\n                {% endif %}\r\n            {% endif %}\r\n        {% endif %}\r\n    {% endif %}\r\n{% endfor %}\r\n\r\n{# for iosxr #}\r\n{% set ns = namespace(str='') %}\r\n{% for item in lists %}\r\n    {% if item.os == 'iosxr' %}\r\n        {% if item.group != '' %}\r\n            {% if ns.str == '' -%}\r\n                [iosxr:children]\r\n                {% set ns.str = item.group -%}\r\n                {{ item.group }}\r\n            {% else %}\r\n                {% if ns.str != item.group -%}\r\n                {{ item.group }}\r\n                {% set ns.str = item.group %}\r\n               {% endif %}\r\n            {% endif %}\r\n        {% endif %}\r\n    {% endif %}\r\n{% endfor %}\r\n\r\n{# for nxos #}\r\n{% set ns = namespace(str='') %}\r\n{% for item in lists %}\r\n    {% if item.os == 'nxos' %}\r\n        {% if item.group != '' %}\r\n            {% if ns.str == '' -%}\r\n                [nxos:children]\r\n                {% set ns.str = item.group -%}\r\n                {{ item.group }}\r\n            {% else %}\r\n                {% if ns.str != item.group -%}\r\n                    {{ item.group }}\r\n                {% set ns.str = item.group %}\r\n                {% endif %}\r\n            {% endif %}\r\n        {% endif %}\r\n    {% endif %}\r\n{% endfor %}\r\n\r\n{# create variables for child group #}\r\n{# for ios #}\r\n{% set ns2 = namespace(str='') %}\r\n{% set ns3 = namespace(str='') %}\r\n{% for item in lists %}\r\n    {% if item.os == 'ios' %}\r\n        {% if item.group != '' %}\r\n            {% if ns2.str == '' -%}\r\n                {{ '[' + item.group + ']' }}\r\n                {% set ns2.str = item.group -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% elif ns2.str == item.group -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% elif ns2.str != item.group -%}\r\n                {{ '[' + item.group + ']' }}\r\n                {% set ns2.str = item.group -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% endif %}\r\n        {% elif item.group == '' %}\r\n            {% if ns3.str == '' -%}\r\n                {{ '[' + item.os + ']' }}\r\n                {% set ns3.str = item.os -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% elif ns3.str == item.os -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% elif ns3.str != item.os -%}\r\n                {{ '[' + item.os + ']' }}\r\n                {% set ns3.str = item.os -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% endif %}\r\n        {% endif %}\r\n    {% endif %}\r\n{% endfor %}\r\n\r\n{# for iosxr #}\r\n{% set ns2 = namespace(str='') %}\r\n{% set ns3 = namespace(str='') %}\r\n{% for item in lists %}\r\n    {% if item.os == 'iosxr' %}\r\n        {% if item.group != '' %}\r\n                {% if ns2.str == '' -%}\r\n                    {{ '[' + item.group + ']' }}\r\n                    {% set ns2.str = item.group -%}\r\n                    {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n                {% elif ns2.str == item.group -%}\r\n                    {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n                {% elif ns2.str != item.group -%}\r\n                    {{ '[' + item.group + ']' }}\r\n                    {% set ns2.str = item.group -%}\r\n                    {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n                {% endif %}\r\n        {% elif item.group == '' %}\r\n                {% if ns3.str == '' -%}\r\n                    {{ '[' + item.os + ']' }}\r\n                    {% set ns3.str = item.os -%}\r\n                    {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n                {% elif ns3.str == item.os -%}\r\n                    {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n                {% elif ns3.str != item.os -%}\r\n                    {{ '[' + item.os + ']' }}\r\n                    {% set ns3.str = item.os -%}\r\n                    {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n                {% endif %}\r\n        {% endif %}\r\n    {% endif %}\r\n{% endfor %}\r\n\r\n{# for nxos #}\r\n{% set ns2 = namespace(str='') %}\r\n{% set ns3 = namespace(str='') %}\r\n{% for item in lists %}\r\n    {% if item.os == 'nxos' %}\r\n        {% if item.group != '' %}\r\n            {% if ns2.str == '' -%}\r\n                {{ '[' + item.group + ']' }}\r\n                {% set ns2.str = item.group -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% elif ns2.str == item.group -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% elif ns2.str != item.group -%}\r\n                {{ '[' + item.group + ']' }}\r\n                {% set ns2.str = item.group -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% endif %}\r\n        {% elif item.group == '' %}\r\n            {% if ns3.str == '' -%}\r\n                {{ '[' + item.os + ']' }}\r\n                {% set ns3.str = item.os -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% elif ns3.str == item.os -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% elif ns3.str != item.os -%}\r\n                {{ '[' + item.os + ']' }}\r\n                {% set ns3.str = item.os -%}\r\n                {{ item.host + ' ansible_host=' + item.ip + ' ansible_ssh_user=' + item.Username + ' ansible_ssh_pass=' + item.Password }}\r\n            {% endif %}\r\n        {% endif %}\r\n    {% endif %}\r\n{% endfor %}\r\n\r\n[all:vars]\r\nansible_connection=network_cli\r\n\r\n{# create [ios:vars] #}\r\n{% set ns4 = namespace(str='') %}\r\n{% for item in lists %}\r\n    {% if item.os == 'ios' -%}\r\n        {% if item.group == '' -%}\r\n            {% if ns4.str == '' -%}\r\n                [ios:vars]\r\n            {% endif %}\r\n            {% if ns4.str  == ''  -%}\r\n                ansible_network_os=ios\r\n            {% endif %}\r\n            {% if ns4.str  == ''  -%}\r\n                commands_show=ios_show.txt\r\n            {% endif %}\r\n            {% if ns4.str  == ''  -%}\r\n                commands_route=ios_route.txt\r\n            {% endif %}\r\n            {% set ns4.str = item.os -%}\r\n        {% elif item.group != '' %}\r\n            {% if ns4.str  == '' -%}\r\n                [ios:vars]\r\n            {% endif %}\r\n            {% if ns4.str == '' -%}\r\n                ansible_network_os=ios\r\n\r\n            {% endif %}\r\n            {% if ns4.str != item.group -%}\r\n                {{ '[' + item.group + ':vars]' }}\r\n            {% endif %}\r\n            {% if ns4.str != item.group -%}\r\n                {{ 'commands_show=' + item.group + '_show.txt' }}\r\n            {% endif %}\r\n            {% if ns4.str != item.group -%}\r\n                {{ 'commands_route=' + item.group + '_route.txt' }}\r\n            {% endif %}\r\n\r\n            {% set ns4.str = item.group -%}\r\n        {% endif %}\r\n    {% endif %}\r\n{% endfor %}\r\n\r\n{# create [iosxr:vars] #}\r\n{% set ns4 = namespace(str='') %}\r\n{% for item in lists %}\r\n    {% if item.os == 'iosxr' -%}\r\n        {% if item.group == '' -%}\r\n            {% if ns4.str == '' -%}\r\n                [iosxr:vars]\r\n            {% endif %}\r\n            {% if ns4.str  == ''  -%}\r\n                ansible_network_os=iosxr\r\n            {% endif %}\r\n            {% if ns4.str == '' -%}\r\n                commands_show=iosxr_show.txt\r\n            {% endif %}\r\n            {% if ns4.str == '' -%}\r\n                commands_route=iosxr_route.txt\r\n            {% endif %}\r\n            {% set ns4.str = item.os -%}\r\n        {% elif item.group != '' %}\r\n            {% if ns4.str  == '' -%}\r\n                [iosxr:vars]\r\n            {% endif %}\r\n            {% if ns4.str  == '' -%}\r\n                ansible_network_os=iosxr\r\n\r\n            {% endif %}\r\n            {% if ns4.str  != item.group  -%}\r\n                {{ '[' + item.group + ':vars]' }}\r\n            {% endif %}\r\n            {% if ns4.str != item.group -%}\r\n                {{ 'commands_show=' + item.group + '_show.txt' }}\r\n            {% endif %}\r\n            {% if ns4.str != item.group -%}\r\n                {{ 'commands_route=' + item.group + '_route.txt' }}\r\n            {% endif %}\r\n\r\n            {% set ns4.str = item.group -%}\r\n        {% endif %}\r\n    {% endif %}\r\n{% endfor %}\r\n\r\n{# create [nxos:vars] #}\r\n{% set ns4 = namespace(str='') %}\r\n{% for item in lists %}\r\n    {% if item.os == 'nxos' -%}\r\n        {% if item.group == '' -%}\r\n            {% if ns4.str == '' -%}\r\n                [nxos:vars]\r\n            {% endif %}\r\n            {% if ns4.str == '' -%}\r\n                ansible_network_os=nxos\r\n            {% endif %}\r\n            {% if ns4.str == '' -%}\r\n                commands_show=nxos_show.txt\r\n            {% endif %}\r\n            {% if ns4.str == '' -%}\r\n                commands_route=nxos_route.txt\r\n            {% endif %}\r\n            {% set ns4.str = item.os -%}\r\n        {% elif item.group != '' %}\r\n            {% if ns4.str  == '' -%}\r\n                [nxos:vars]\r\n            {% endif %}\r\n            {% if ns4.str == '' -%}\r\n                ansible_network_os=nxos\r\n\r\n            {% endif %}\r\n            {% if ns4.str != item.group  -%}\r\n                {{ '[' + item.group + ':vars]' }}\r\n                {% if ns4.str != item.group -%}\r\n                    {{ 'commands_show=' + item.group + '_show.txt' }}\r\n                {% endif %}\r\n                 {% if ns4.str != item.group -%}\r\n                    {{ 'commands_route=' + item.group + '_route.txt' }}\r\n\r\n                {% endif %}\r\n                {% set ns4.str = item.group -%}\r\n            {% endif %}\r\n        {% endif %}\r\n    {% endif %}\r\n{% endfor %}\r\n\r\n\r\n\r\n<\/code><\/pre>\n<h1>\u6267\u884c\u7ed3\u679c<\/h1>\n<p>\u9644\u4e0a\u6267\u884cAnsible-playbook\u547d\u4ee4\u7684\u65e5\u5fd7\uff0c\u56e0\u4e3a\u5df2\u7ecf\u751f\u6210\u4e86\u6587\u4ef6\u5e76\u5df2\u586b\u5199\u3002<\/p>\n<pre class=\"post-pre\"><code>\u276f ansible-playbook -i localhost template.yml\r\n[WARNING]: Unable to parse \/Users\/tomohidekimura\/Documents\/ansible\/template-test\/health_check\/localhost as an inventory source\r\n[WARNING]: No inventory was parsed, only implicit localhost is available\r\n[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'\r\n\r\nPLAY [localhost] *********************************************************************************************************************************************\r\n\r\nTASK [read inventory csv] ************************************************************************************************************************************\r\nok: [localhost]\r\n\r\nTASK [display] ***********************************************************************************************************************************************\r\nok: [localhost] =&gt; {\r\n    \"msg\": [\r\n        {\r\n            \"Password\": \"cisco\",\r\n            \"Username\": \"cisco\",\r\n            \"group\": \"l2\",\r\n            \"host\": \"edge-sw01\",\r\n            \"ip\": \"10.10.20.172\",\r\n            \"os\": \"ios\"\r\n        },\r\n        {\r\n            \"Password\": \"cisco\",\r\n            \"Username\": \"cisco\",\r\n            \"group\": \"dist\",\r\n            \"host\": \"dist-rtr01\",\r\n            \"ip\": \"10.10.20.175\",\r\n            \"os\": \"ios\"\r\n        },\r\n        {\r\n            \"Password\": \"cisco\",\r\n            \"Username\": \"cisco\",\r\n            \"group\": \"dist\",\r\n            \"host\": \"dist-rtr02\",\r\n            \"ip\": \"10.10.20.176\",\r\n            \"os\": \"ios\"\r\n        },\r\n        {\r\n            \"Password\": \"cisco\",\r\n            \"Username\": \"cisco\",\r\n            \"group\": \"internet\",\r\n            \"host\": \"internet-rtr01\",\r\n            \"ip\": \"10.10.20.181\",\r\n            \"os\": \"ios\"\r\n        },\r\n        {\r\n            \"Password\": \"cisco\",\r\n            \"Username\": \"cisco\",\r\n            \"group\": \"\",\r\n            \"host\": \"dist_sw01\",\r\n            \"ip\": \"10.10.20.178\",\r\n            \"os\": \"nxos\"\r\n        },\r\n        {\r\n            \"Password\": \"cisco\",\r\n            \"Username\": \"cisco\",\r\n            \"group\": \"\",\r\n            \"host\": \"dist_sw02\",\r\n            \"ip\": \"10.10.20.179\",\r\n            \"os\": \"nxos\"\r\n        },\r\n        {\r\n            \"Password\": \"cisco\",\r\n            \"Username\": \"cisco\",\r\n            \"group\": \"\",\r\n            \"host\": \"core-rtr01\",\r\n            \"ip\": \"10.10.20.173\",\r\n            \"os\": \"iosxr\"\r\n        },\r\n        {\r\n            \"Password\": \"cisco\",\r\n            \"Username\": \"cisco\",\r\n            \"group\": \"\",\r\n            \"host\": \"core-rtr02\",\r\n            \"ip\": \"10.10.20.174\",\r\n            \"os\": \"iosxr\"\r\n        }\r\n    ]\r\n}\r\n\r\nTASK [set command requests] **********************************************************************************************************************************\r\nok: [localhost]\r\n\r\nTASK [create inventory] **************************************************************************************************************************************\r\nchanged: [localhost]\r\n\r\nPLAY RECAP ***************************************************************************************************************************************************\r\nlocalhost                  : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0\r\n<\/code><\/pre>\n<p>\u4e00\u5207\u987a\u5229\u5b8c\u6210\u4e86\uff01<\/p>\n<h1>\u6700\u540e<\/h1>\n<p>\u5c3d\u7ba1\u5916\u89c2\u4e0d\u5bf9\u79f0\uff0c\u4f46\u6211\u6210\u529f\u5730\u521b\u5efa\u4e86\u6240\u9700\u7684\u6e05\u5355\u6587\u4ef6\u3002<br \/>\n\u56e0\u4e3a\u6211\u6ca1\u6709\u9884\u6599\u5230\u4f1a\u53d8\u5f97\u8fd9\u4e48\u957f\uff0c\u5c31\u9c81\u83bd\u5730\u5f00\u59cb\u4e86\u5de5\u4f5c\uff0c\u7ed3\u679c\u751f\u6210\u4e86\u4e00\u5806\u6742\u4e71\u65e0\u7ae0\u7684\u6587\u4ef6\u3002<br \/>\n\u5728\u8fc7\u7a0b\u4e2d\uff0c\u6211\u53d1\u73b0\u6a21\u677f\u6587\u4ef6\u5185\u7684\u53d8\u91cf\u8fd8\u6709\u4f5c\u7528\u57df\u95ee\u9898\uff0c\u5e76\u4e14\u65e0\u6cd5\u8fd0\u884c\u4e0eif\u8bed\u53e5\u7ed3\u5408\u7684loop.index\u7b49\u7b49\uff0c<br \/>\n\u6211\u82b1\u4e86\u5f88\u591a\u65f6\u95f4\u89e3\u51b3\u8fd9\u4e9b\u610f\u5916\u60c5\u51b5&#8230;\u56e0\u4e3a\u4e0d\u77e5\u9053\u5982\u4f55\u8fdb\u884c\u8c03\u8bd5\uff0c\u6240\u4ee5\u975e\u5e38\u56f0\u96be\u3002<br \/>\n\u672a\u6765\uff0c\u6211\u5e0c\u671b\u521b\u5efa\u4e00\u4e2a\u751f\u6210\u7ec4\u53d8\u91cf\u6a21\u677f\u548c\u83b7\u53d6\u547d\u4ee4\u5217\u8868\u6587\u4ef6\u7684Playbook\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148 \u6211\u4e4b\u524d\u7528Ansible\u521b\u5efa\u4e86\u4e00\u4e2a\u53ef\u4ee5\u83b7\u53d6\u65e5\u5fd7\u7684playbook\u3002 \u53ea\u9700\u66f4\u65b0playbook\u672c\u8eab\u7684\u76ee\u5f55\u4fe1\u606f [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-42422","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528Ansible\u548cJinja\u4eceCSV\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ansible\u548cjinja\u4ececsv\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528Ansible\u548cJinja\u4eceCSV\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6\" \/>\n<meta property=\"og:description\" content=\"\u9996\u5148 \u6211\u4e4b\u524d\u7528Ansible\u521b\u5efa\u4e86\u4e00\u4e2a\u53ef\u4ee5\u83b7\u53d6\u65e5\u5fd7\u7684playbook\u3002 \u53ea\u9700\u66f4\u65b0playbook\u672c\u8eab\u7684\u76ee\u5f55\u4fe1\u606f [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ansible\u548cjinja\u4ececsv\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T15:12:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T03:52:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d4ca937434c4406cbb633\/7-0.jpeg\" \/>\n<meta name=\"author\" content=\"\u79d1, \u96c5\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u79d1, \u96c5\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/\",\"name\":\"\u4f7f\u7528Ansible\u548cJinja\u4eceCSV\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-07-23T15:12:27+00:00\",\"dateModified\":\"2024-04-30T03:52:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528Ansible\u548cJinja\u4eceCSV\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\",\"name\":\"\u79d1, \u96c5\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"caption\":\"\u79d1, \u96c5\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528Ansible\u548cJinja\u4eceCSV\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ansible\u548cjinja\u4ececsv\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528Ansible\u548cJinja\u4eceCSV\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6","og_description":"\u9996\u5148 \u6211\u4e4b\u524d\u7528Ansible\u521b\u5efa\u4e86\u4e00\u4e2a\u53ef\u4ee5\u83b7\u53d6\u65e5\u5fd7\u7684playbook\u3002 \u53ea\u9700\u66f4\u65b0playbook\u672c\u8eab\u7684\u76ee\u5f55\u4fe1\u606f [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ansible\u548cjinja\u4ececsv\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-07-23T15:12:27+00:00","article_modified_time":"2024-04-30T03:52:07+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d4ca937434c4406cbb633\/7-0.jpeg"}],"author":"\u79d1, \u96c5","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u79d1, \u96c5","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/","name":"\u4f7f\u7528Ansible\u548cJinja\u4eceCSV\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-07-23T15:12:27+00:00","dateModified":"2024-04-30T03:52:07+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528Ansible\u548cJinja\u4eceCSV\u6587\u4ef6\u521b\u5efa\u6e05\u5355\u6587\u4ef6"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a","name":"\u79d1, \u96c5","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","caption":"\u79d1, \u96c5"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%92%8cjinja%e4%bb%8ecsv%e6%96%87%e4%bb%b6%e5%88%9b%e5%bb%ba%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=42422"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42422\/revisions"}],"predecessor-version":[{"id":91747,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42422\/revisions\/91747"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=42422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=42422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=42422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}