Repository: ansible/ansible

Issue:
vault-keyring.py fails with "object has no attribute 'load_config_file'"
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
./contrib/vault/vault-keyring.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
$ ansible --version
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/jonasj/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Sep  5 2017, 08:53:59) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Fedora 26

##### SUMMARY
<!--- Explain the problem briefly -->
```
$ ./contrib/vault/vault-keyring.py
Traceback (most recent call last):
  File "./contrib/vault/vault-keyring.py", line 101, in <module>
    main()
  File "./contrib/vault/vault-keyring.py", line 72, in main
    (parser, config_path) = C.load_config_file()
AttributeError: 'module' object has no attribute 'load_config_file'
```
##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
```
# Running from git repo commit 54ca841611
$ ./contrib/vault/vault-keyring.py
```


Discussion:

Resolving patch:
diff --git a/contrib/vault/vault-keyring.py b/contrib/vault/vault-keyring.py
--- a/contrib/vault/vault-keyring.py
+++ b/contrib/vault/vault-keyring.py
@@ -65,20 +65,20 @@
 import getpass
 import keyring
 
-import ansible.constants as C
+from ansible.config.manager import ConfigManager, get_ini_config_value
 
 
 def main():
-    (parser, config_path) = C.load_config_file()
-    if parser.has_option('vault', 'username'):
-        username = parser.get('vault', 'username')
-    else:
-        username = getpass.getuser()
+    config = ConfigManager()
+    username = get_ini_config_value(
+        config._parser,
+        dict(section='vault', key='username')
+    ) or getpass.getuser()
 
-    if parser.has_option('vault', 'keyname'):
-        keyname = parser.get('vault', 'keyname')
-    else:
-        keyname = 'ansible'
+    keyname = get_ini_config_value(
+        config._parser,
+        dict(section='vault', key='keyname')
+    ) or 'ansible'
 
     if len(sys.argv) == 2 and sys.argv[1] == 'set':
         intro = 'Storing password in "{}" user keyring using key name: {}\n'


Test patch: