# Problems setting DEFAULT\_LOG\_PATH in Python

**URL:** <https://forum.ansible.com/t/problems-setting-default-log-path-in-python/21237>\
**Category:** Ansible Project\
**Created:** [April 21, 2016, 6:38pm UTC](https://forum.ansible.com/t/problems-setting-default-log-path-in-python/21237 "2016-04-21T18:38:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Locom](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Locom](https://forum.ansible.com/u/Locom)\
**Post date:** [April 21, 2016, 6:38pm UTC](https://forum.ansible.com/t/problems-setting-default-log-path-in-python/21237/1 "2016-04-21T18:38:55Z")

</div>

Hello folks,

I’m new to Python/Ansible and I’m running into a problem that’s stumped me for 2 days. I’m trying to modify the DEFAULT\_LOG\_PATH variable in Python (the log file name will be date based). The setup below works on my local machine i.e it writes logs to the location set in my Python code. However, it fails on a the actual deployment machine. It seems like my DEFAULT\_LOG\_PATH doesn’t get set because Ansible still writes the logs to the default DEFAULT\_LOG\_PATH i.e /var/log/ansible.log

I suspect that the differing Python versions are the culprit. Upgrading the deployment machine to 2.7.10 might be a solution but we don’t want to do that if we don’t know for sure if that will fix the problem.

Local machine: Python v2.7.10, Ansible v1.9.4  
Deployment machine: Python v2.6.6 and Ansible 1.9.4

All my import declarations:

import argparse  
import getpass  
import sys  
import datetime  
import os

import ansible.runner  
import ansible.playbook  
import ansible.inventory  
from ansible import errors  
from ansible import callbacks  
from ansible.callbacks import display  
from ansible import utils  
from ansible.color import ANSIBLE\_COLOR, stringc  
from ansible import constants as ANSIBLE\_CONSTANTS

The log\_path modifier excerpt (for brevity):

logFile = “ansible\_” + environment + “\_” + datetime.date.today().strftime(‘%Y%m%d’) +“.log” #e.g ansible\_prod\_20160408.log  
if environment != ‘dev’ and os.path.isdir(“/usr/local/releases/logs”) and os.access(“/usr/local/releases/logs”, os.W\_OK ):  
ANSIBLE\_CONSTANTS.DEFAULT\_LOG\_PATH = “/usr/local/releases/logs/” + logFile  
else:  
ANSIBLE\_CONSTANTS.DEFAULT\_LOG\_PATH = logFile  
reload(callbacks)

Note: “reload(callbacks)” is outside the else block.

Any ideas as to what I may be missing?
