<linkrel="next"title="community.routeros.api module – Ansible module for RouterOS API"href="../api_module.html"/>
<linkrel="prev"title="How to connect to RouterOS devices with SSH"href="ssh-guide.html"/><!-- extra head elements for Ansible beyond RTD Sphinx Theme -->
</head>
<bodyclass="wy-body-for-nav"><!-- extra body elements for Ansible beyond RTD Sphinx Theme -->
<liclass="toctree-l1"><aclass="reference internal"href="api-guide.html">How to connect to RouterOS devices with the RouterOS API</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="ssh-guide.html">How to connect to RouterOS devices with SSH</a></li>
<liclass="toctree-l1 current"><aclass="current reference internal"href="#">How to quote and unquote commands and arguments</a></li>
</ul>
<ul>
<liclass="toctree-l1"><aclass="reference internal"href="../api_module.html">community.routeros.api module – Ansible module for RouterOS API</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../api_facts_module.html">community.routeros.api_facts module – Collect facts from remote devices running MikroTik RouterOS using the API</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../api_find_and_modify_module.html">community.routeros.api_find_and_modify module – Find and modify information using the API</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../api_info_module.html">community.routeros.api_info module – Retrieve information from API</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../api_modify_module.html">community.routeros.api_modify module – Modify data at paths with API</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../command_module.html">community.routeros.command module – Run commands on remote devices running MikroTik RouterOS</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../routeros_cliconf.html">community.routeros.routeros cliconf – Use routeros cliconf to run command on MikroTik RouterOS platform</a></li>
</ul>
<ul>
<liclass="toctree-l1"><aclass="reference internal"href="../join_filter.html">community.routeros.join filter – Join a list of arguments to a command</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../list_to_dict_filter.html">community.routeros.list_to_dict filter – Convert a list of arguments to a dictionary</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../quote_argument_filter.html">community.routeros.quote_argument filter – Quote an argument</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../quote_argument_value_filter.html">community.routeros.quote_argument_value filter – Quote an argument value</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="../split_filter.html">community.routeros.split filter – Split a command into arguments</a></li>
</ul>
<!-- extra nav elements for Ansible beyond RTD Sphinx Theme -->
<spanid="ansible-collections-community-routeros-docsite-quoting"></span><h1>How to quote and unquote commands and arguments<aclass="headerlink"href="#how-to-quote-and-unquote-commands-and-arguments"title="Link to this heading"></a></h1>
<p>When using the <aclass="reference internal"href="../command_module.html#ansible-collections-community-routeros-command-module"><spanclass="std std-ref">community.routeros.command module</span></a> or the <aclass="reference internal"href="../api_module.html#ansible-collections-community-routeros-api-module"><spanclass="std std-ref">community.routeros.api module</span></a> modules, you need to pass text data in quoted form. While in some cases quoting is not needed (when passing IP addresses or names without spaces, for example), in other cases it is required, like when passing a comment which contains a space.</p>
<p>The community.routeros collection provides a set of Jinja2 filter plugins which helps you with these tasks:</p>
<li><p>The <aclass="reference internal"href="../quote_argument_filter.html#ansible-collections-community-routeros-quote-argument-filter"><spanclass="std std-ref">community.routeros.quote_argument filter</span></a> quotes an argument with or without a value: <codeclass="docutils literal notranslate"><spanclass="pre">'comment=this</span><spanclass="pre">is</span><spanclass="pre">a</span><spanclass="pre">"comment"'</span><spanclass="pre">|</span><spanclass="pre">community.routeros.quote_argument</span><spanclass="pre">==</span><spanclass="pre">'comment="this</span><spanclass="pre">is</span><spanclass="pre">a</span><spanclass="pre">\\"comment\\""'</span></code>.</p></li>
<li><p>The <aclass="reference internal"href="../join_filter.html#ansible-collections-community-routeros-join-filter"><spanclass="std std-ref">community.routeros.join filter</span></a> quotes a list of arguments and joins them to one string: <codeclass="docutils literal notranslate"><spanclass="pre">['foo=bar',</span><spanclass="pre">'comment=foo</span><spanclass="pre">is</span><spanclass="pre">bar']</span><spanclass="pre">|</span><spanclass="pre">community.routeros.join</span><spanclass="pre">==</span><spanclass="pre">'foo=bar</span><spanclass="pre">comment="foo</span><spanclass="pre">is</span><spanclass="pre">bar"'</span></code>.</p></li>
<li><p>The <aclass="reference internal"href="../split_filter.html#ansible-collections-community-routeros-split-filter"><spanclass="std std-ref">community.routeros.split filter</span></a> splits a command into a list of arguments (with or without values): <codeclass="docutils literal notranslate"><spanclass="pre">'foo=bar</span><spanclass="pre">comment="foo</span><spanclass="pre">is</span><spanclass="pre">bar"'</span><spanclass="pre">|</span><spanclass="pre">community.routeros.split</span><spanclass="pre">==</span><spanclass="pre">['foo=bar',</span><spanclass="pre">'comment=foo</span><spanclass="pre">is</span><spanclass="pre">bar']</span></code></p></li>
<li><p>The <aclass="reference internal"href="../list_to_dict_filter.html#ansible-collections-community-routeros-list-to-dict-filter"><spanclass="std std-ref">community.routeros.list_to_dict filter</span></a> splits a list of arguments with values into a dictionary: <codeclass="docutils literal notranslate"><spanclass="pre">['foo=bar',</span><spanclass="pre">'comment=foo</span><spanclass="pre">is</span><spanclass="pre">bar']</span><spanclass="pre">|</span><spanclass="pre">community.routeros.list_to_dict</span><spanclass="pre">==</span><spanclass="pre">{'foo':</span><spanclass="pre">'bar',</span><spanclass="pre">'comment':</span><spanclass="pre">'foo</span><spanclass="pre">is</span><spanclass="pre">bar'}</span></code>. It has two optional arguments: <codeclass="ansible-option docutils literal notranslate"><strong><aclass="reference internal"href="../list_to_dict_filter.html#ansible-collections-community-routeros-list-to-dict-filter-parameter-require-assignment"><spanclass="std std-ref"><spanclass="pre">require_assignment</span></span></a></strong></code> (default value <codeclass="ansible-value docutils literal notranslate"><spanclass="pre">true</span></code>) allows to accept arguments without values when set to <codeclass="ansible-value docutils literal notranslate"><spanclass="pre">false</span></code>; and <codeclass="ansible-option docutils literal notranslate"><strong><aclass="reference internal"href="../list_to_dict_filter.html#ansible-collections-community-routeros-list-to-dict-filter-parameter-skip-empty-values"><spanclass="std std-ref"><spanclass="pre">skip_empty_values</span></span></a></strong></code> (default value <codeclass="ansible-value docutils literal notranslate"><spanclass="pre">false</span></code>) allows to skip arguments whose value is empty.</p></li>
<ahref="ssh-guide.html"class="btn btn-neutral float-left"title="How to connect to RouterOS devices with SSH"accesskey="p"rel="prev"><spanclass="fa fa-arrow-circle-left"aria-hidden="true"></span> Previous</a>