<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<ul dir="auto">
<li>bigip_virtual_server Module</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.5.0
  config file = None
  configured module search path = [u'/home/asavinykh/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]"><pre class="notranslate"><code class="notranslate">ansible 2.5.0
  config file = None
  configured module search path = [u'/home/asavinykh/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">Default</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<ul dir="auto">
<li>Control machine: ubuntu linux 16.04LTS</li>
<li>Managed node: BIG-IP 12.1.2 Build 1.0.271 Hotfix HF1</li>
</ul>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When creating a virtual server I would like to configure both Client and Server protocol profiles, which are different profiles as shown on the picture:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/27190911/31971159-1383b530-b977-11e7-97f4-27c9c388632a.png"><img src="https://user-images.githubusercontent.com/27190911/31971159-1383b530-b977-11e7-97f4-27c9c388632a.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">It is currently impossible to achieve it with the ansible module. <a href="https://devcentral.f5.com/wiki/iControl.LocalLB__ProfileContextType.ashx" rel="nofollow">This enumeration</a> is used to specify if the profile client or server. But the ansible module always passes PROFILE_CONTEXT_TYPE_ALL as can be seen <a href="https://github.com/ansible/ansible/blob/f3f0ba87cef4e6dffe7982a64e8d0fd4f19f4b72/lib/ansible/modules/network/f5/bigip_virtual_server.py#L221">here</a>, <a href="https://github.com/ansible/ansible/blob/f3f0ba87cef4e6dffe7982a64e8d0fd4f19f4b72/lib/ansible/modules/network/f5/bigip_virtual_server.py#L306">here</a> and <a href="https://github.com/ansible/ansible/blob/f3f0ba87cef4e6dffe7982a64e8d0fd4f19f4b72/lib/ansible/modules/network/f5/bigip_virtual_server.py#L310">here</a>. As a result if you try to pass both client and server profiles you get a error.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Run a playbook that has the following yaml fragment:</p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  - name: Add virtual server
    bigip_virtual_server:
      server: &quot;{{ f5_server }}&quot;
      password: &quot;{{ f5_password }}&quot;
      user: &quot;{{ f5_user }}&quot;
      validate_certs: &quot;no&quot;
      state: &quot;{{ f5_state }}&quot;
      partition: WWW
      name: &quot;{{ item.name }}&quot;
      destination: &quot;{{ item.ip }}&quot;
      port: 80
      pool: &quot;{{ item.pool }}&quot;
      all_profiles:
        - /Common/Default_WAN_optimized_TCP_Profile
        - /Common/Default_LAN_optimized_TCP_Profile
        - /Common/Insert_X-Forward_http_profile
        - /Common/Default_OneConnect_Profile
        - /Common/Default_wan-optimized-compression_profile
      default_persistence_profile: /Common/Default_cookie_persistence_profile
      fallback_persistence_profile: /Common/Default_source-addr-persistence_profile
    delegate_to: localhost
    with_items: &quot;{{ servers }}&quot;"><pre class="notranslate">  - <span class="pl-ent">name</span>: <span class="pl-s">Add virtual server</span>
    <span class="pl-ent">bigip_virtual_server</span>:
      <span class="pl-ent">server</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ f5_server }}<span class="pl-pds">"</span></span>
      <span class="pl-ent">password</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ f5_password }}<span class="pl-pds">"</span></span>
      <span class="pl-ent">user</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ f5_user }}<span class="pl-pds">"</span></span>
      <span class="pl-ent">validate_certs</span>: <span class="pl-s"><span class="pl-pds">"</span>no<span class="pl-pds">"</span></span>
      <span class="pl-ent">state</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ f5_state }}<span class="pl-pds">"</span></span>
      <span class="pl-ent">partition</span>: <span class="pl-s">WWW</span>
      <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.name }}<span class="pl-pds">"</span></span>
      <span class="pl-ent">destination</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.ip }}<span class="pl-pds">"</span></span>
      <span class="pl-ent">port</span>: <span class="pl-c1">80</span>
      <span class="pl-ent">pool</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.pool }}<span class="pl-pds">"</span></span>
      <span class="pl-ent">all_profiles</span>:
        - <span class="pl-s">/Common/Default_WAN_optimized_TCP_Profile</span>
        - <span class="pl-s">/Common/Default_LAN_optimized_TCP_Profile</span>
        - <span class="pl-s">/Common/Insert_X-Forward_http_profile</span>
        - <span class="pl-s">/Common/Default_OneConnect_Profile</span>
        - <span class="pl-s">/Common/Default_wan-optimized-compression_profile</span>
      <span class="pl-ent">default_persistence_profile</span>: <span class="pl-s">/Common/Default_cookie_persistence_profile</span>
      <span class="pl-ent">fallback_persistence_profile</span>: <span class="pl-s">/Common/Default_source-addr-persistence_profile</span>
    <span class="pl-ent">delegate_to</span>: <span class="pl-s">localhost</span>
    <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ servers }}<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">Note that both <code class="notranslate">Default_WAN_optimized_TCP_Profile</code> and <code class="notranslate">Default_LAN_optimized_TCP_Profile</code> are TCP protocol profiles.</p>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">There should be a way for ansible module to tell apart client and server profile. Ideally <a href="https://devcentral.f5.com/wiki/iControl.LocalLB__VirtualServer__VirtualServerProfile.ashx" rel="nofollow">profile_context</a> should be part of the module <a href="http://docs.ansible.com/ansible/latest/bigip_virtual_server_module.html" rel="nofollow">options</a>.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">A error is produced:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="failed: [xxx.xxx.xxx.xxx -&gt; localhost] (item={u'ip': u'xxx.xxx.xxx.xxx', u'name': u'www.website.com_HTTP_VS_as', u'pool': u'www.website.com_HTTP_pool_as'}) =&gt; {&quot;changed&quot;: false, &quot;item&quot;: {&quot;ip&quot;: &quot;xxx.xxx.xxx.xxx&quot;, &quot;name&quot;: &quot;www.website.com_HTTP_VS_as&quot;, &quot;pool&quot;: &quot;www.website.com_HTTP_pool_as&quot;}, &quot;msg&quot;: &quot;received exception: Error on updating Virtual Server : Server raised fault: 'Exception caught in System::urn:iControl:System/Session::submit_transaction()\nException: Common::OperationFailed\n\tprimary_error_code   : 17236119 (0x01070097)\n\tsecondary_error_code : 0\n\terror_string         : 01070097:3: Virtual server /WWW/www.website.com_HTTP_VS_as lists duplicate profiles.'&quot;}"><pre lang="text" class="notranslate"><code class="notranslate">failed: [xxx.xxx.xxx.xxx -&gt; localhost] (item={u'ip': u'xxx.xxx.xxx.xxx', u'name': u'www.website.com_HTTP_VS_as', u'pool': u'www.website.com_HTTP_pool_as'}) =&gt; {"changed": false, "item": {"ip": "xxx.xxx.xxx.xxx", "name": "www.website.com_HTTP_VS_as", "pool": "www.website.com_HTTP_pool_as"}, "msg": "received exception: Error on updating Virtual Server : Server raised fault: 'Exception caught in System::urn:iControl:System/Session::submit_transaction()\nException: Common::OperationFailed\n\tprimary_error_code   : 17236119 (0x01070097)\n\tsecondary_error_code : 0\n\terror_string         : 01070097:3: Virtual server /WWW/www.website.com_HTTP_VS_as lists duplicate profiles.'"}
</code></pre></div>
<p dir="auto">I am using ansible 2.3.0.0 running it within an docker-container</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="root@880299e5edbc:/# ansible --version
ansible 2.3.0.0
config file =
configured module search path = Default w/o overrides
python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]`"><pre class="notranslate">root@880299e5edbc:/<span class="pl-c"><span class="pl-c">#</span> ansible --version</span>
ansible 2.3.0.0
config file =
configured module search path = Default w/o overrides
python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]<span class="pl-s"><span class="pl-pds">`</span></span></pre></div>
<p dir="auto">The following task works. Ansible writes the line "hello... " to the /tmp/list of the delegated hosts.</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: my-task
  action: shell echo &quot;hello I am on the delegate host&quot; &gt;&gt; /tmp/list
  delegate_to: &quot;{{ item }}&quot;
  with_items: &quot;{{ hosts }}&quot;"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">my-task</span>
  <span class="pl-ent">action</span>: <span class="pl-s">shell echo "hello I am on the delegate host" &gt;&gt; /tmp/list</span>
  <span class="pl-ent">delegate_to</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ hosts }}<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">When writing the same task using loop_vars it doesn't work. Ansible seems not to be able to connect to the delegated hosts, writing "Name or service not known" to the console.</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: my-task
  action: shell echo &quot;hello I am on the delegate host&quot; &gt;&gt; /tmp/list
  delegate_to: &quot;{{ myVar }}&quot;
  with_items: &quot;{{ hosts }}&quot;
  loop_control: 
    loop_var: myVar"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">my-task</span>
  <span class="pl-ent">action</span>: <span class="pl-s">shell echo "hello I am on the delegate host" &gt;&gt; /tmp/list</span>
  <span class="pl-ent">delegate_to</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ myVar }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ hosts }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">loop_control</span>: 
    <span class="pl-ent">loop_var</span>: <span class="pl-s">myVar</span></pre></div>