title: How to set ansible configuration variables run time
body: <p>I need to set some ansible configuration variables during execution within the playbook. I tried following, but its not working:</p>
  
  <pre><code>--&gt; cat site.yml
  - hosts: localhost
    tasks:
      - set_fact:
          log_path: "/home/monk/test/ansible_set_run_time"
  
  - hosts: localhost
    environment:
      log_path: "{{ log_path }}"
    tasks:
      - shell: "echo $log_path"
        register: res
  
      - debug:
          msg: "log_path = {{ res.stdout }}"
  </code></pre>
  
  <p><code>ansible.cfg</code> content at the current directory:</p>
  
  <pre><code>--&gt;cat /home/monk/test/ansible.cfg
  [defaults]
  log_path = /home/monk/test/ansiblelog_from_cfg
  </code></pre>
  
  <p>This always generate the log file set by <code>/home/monk/test/ansible.cfg</code> and never by the <code>log_path</code> set within the playbook.</p>
  
  <p>Why I do not want to use <code>/etc/ansible/ansible.cfg</code> ,<code>$PWD/ansible.cfg</code> , or <code>$HOME/.ansible.cfg</code> ?</p>
  
  <p>Reason: I will be running this on remote node, where there is a <code>/etc/ansible/ansible.cfg</code> file already present which contains the global settings which I cannot change , At the same time I cannot use <code>$PWD/ansible.cfg</code> because, I also need the content of <code>/etc/ansible/ansible.cfg</code>. </p>
  
  <p>So TLDR, I need to read the contents of <code>/etc/ansible/ansible.cfg</code> and local <code>ansible.cfg</code> and use them both . I can merge them all but I cannot control the changes of <code>/etc/ansible/ansible.cfg</code> so my merged changes may be outdated. This is why I want to define my configuration variable stored within the playbooks and I will keep reading <code>/etc/ansible/ansible.cfg</code>. </p>
  
  <pre><code>ansible --version
  ansible 2.5.2
    config file = /home/monk/.ansible.cfg
    configured module search path = [u'/home/monk/.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.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
  </code></pre>
  
  <p>I can see that <code>set_fact</code> is showing the desired value, but <code>log_path</code> is not coming into the effect for the playbook:</p>
  
  <pre><code>ansible-playbook  -i data.ini  playbook.yml
  
  PLAY [localhost] **********************************************************************************************************************************************************************************************
  
  TASK [Gathering Facts] ****************************************************************************************************************************************************************************************
  ok: [127.0.0.1]
  
  TASK [set_fact] ***********************************************************************************************************************************************************************************************
  ok: [127.0.0.1]
  
  PLAY [localhost] **********************************************************************************************************************************************************************************************
  
  TASK [Gathering Facts] ****************************************************************************************************************************************************************************************
  ok: [127.0.0.1]
  
  TASK [command] ************************************************************************************************************************************************************************************************
  changed: [127.0.0.1]
  
  TASK [debug] **************************************************************************************************************************************************************************************************
  ok: [127.0.0.1] =&gt; {
      "msg": "log_path = /home/monk/test/ansible_set_run_time"
  }
  
  PLAY RECAP ****************************************************************************************************************************************************************************************************
  127.0.0.1                  : ok=5    changed=1    unreachable=0    failed=0
  </code></pre>