<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">gather_facts</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.0.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Jul  1 2016, 15:12:24) [GCC 5.4.0 20160609]"><pre class="notranslate"><code class="notranslate">ansible 2.3.0.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Jul  1 2016, 15:12:24) [GCC 5.4.0 20160609]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">Default configuration (no local ansible.cfg)</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">OS = Ubuntu 16.04.2 LTS</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">If a playbook consists of multiple play, each of which affects distinct set of hosts, when only a subset of play is selected for running, Ansible still tries to gather facts from unaffected hosts. This might be related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="208196466" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/21528" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/21528/hovercard" href="https://github.com/ansible/ansible/issues/21528">#21528</a></p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Run the following playbook <code class="notranslate">ansible-playbook -i dev sample.yml --tags=db</code></p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---

- hosts: mysql
  tags: db
  tasks:
    - debug: msg=hello

- hosts: app
  tags: app
  tasks:
    - debug: msg=world"><pre class="notranslate">---

- <span class="pl-ent">hosts</span>: <span class="pl-s">mysql</span>
  <span class="pl-ent">tags</span>: <span class="pl-s">db</span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">debug</span>: <span class="pl-s">msg=hello</span>

- <span class="pl-ent">hosts</span>: <span class="pl-s">app</span>
  <span class="pl-ent">tags</span>: <span class="pl-s">app</span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">debug</span>: <span class="pl-s">msg=world</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">Facts are not gathered for <code class="notranslate">app</code> hosts</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">Facts are gathered for all hosts</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [mysql] ******************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [172.31.2.4]

TASK [debug] ******************************************************************************************************************************************************************************************************
ok: [172.31.2.4] =&gt; {
    &quot;changed&quot;: false, 
    &quot;msg&quot;: &quot;hello&quot;
}

PLAY [app] ********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [172.31.1.4]

PLAY RECAP ********************************************************************************************************************************************************************************************************
172.31.1.4                : ok=1    changed=0    unreachable=0    failed=0   
172.31.2.4                 : ok=2    changed=0    unreachable=0    failed=0   
"><pre class="notranslate"><code class="notranslate">PLAY [mysql] ******************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [172.31.2.4]

TASK [debug] ******************************************************************************************************************************************************************************************************
ok: [172.31.2.4] =&gt; {
    "changed": false, 
    "msg": "hello"
}

PLAY [app] ********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [172.31.1.4]

PLAY RECAP ********************************************************************************************************************************************************************************************************
172.31.1.4                : ok=1    changed=0    unreachable=0    failed=0   
172.31.2.4                 : ok=2    changed=0    unreachable=0    failed=0   

</code></pre></div>
<p dir="auto">FreeBSD seems very fond of "rc-style" configuration files, which have the following format:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# Comment
SOMETHING=somevalue"><pre class="notranslate"><code class="notranslate"># Comment
SOMETHING=somevalue
</code></pre></div>
<p dir="auto">Examples of this are make.conf, sysctl.conf, rc.conf and many others.</p>
<p dir="auto">The format is close, but not exactly the INI-format, which makes the ini_file module unusable. The lineinfile module works but is wordy and makes the playbook look cumbersome.</p>
<p dir="auto">I'd like to see an rc_file module, that would help in configuring values for such files.</p>
<p dir="auto">I'm nearly volunteering to write one myself, but there is a gotcha. At least the service module contains code that manipulates rc.conf directly to set (some of the values) there. Would it be important to refactor that code into a centralized location and if so, what would that place be? I am not overly familiar with Ansible internals.</p>