Ansible Error reading config file: File contains no section headers

Viewed 6734

SUMMARY

As per documentation for Ansible Configuration Settings, we can place ansible.cfg in current directory of the project we are working on and Ansible will search for a config file in the order specified in link above.

However, it appears that ansible is unable to correctly parse ansible.cfg file within my project directory. I am not sure but I think it has to be with the Ini ConfigParser

ANSIBLE VERSION
  ansible 2.6.3
  config file = /Users/pnotes/Code/Terraform/Blog/ansible/ansible.cfg
  configured module search path = ['/Users/pnotes/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/pnotes/.pyenv/versions/3.6.4/lib/python3.6/site-packages/ansible
  executable location = /Users/pnotes/.pyenv/versions/3.6.4/bin/ansible
  python version = 3.6.4 (default, Feb 26 2018, 21:07:35) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

CONFIGURATION

output of "ansible-config dump --only-changed"

Error reading config file (/Users/pnotes/Code/Terraform/Blog/terraform/ansible.cfg): File contains no section headers.
file: '/Users/pnotes/Code/Terraform/Blog/terraform/ansible.cfg', line: 3
'vault_password_file = ~/.vault_pass.txt\n'

OS / ENVIRONMENT

macOS High Sierra

  • contents of terraform/ansible.cfg:

      # If set, configures the path to the Vault password file as an 
      # alternative to specifying --vault-password-file on the command
      # line.
      vault_password_file = ~/.vault_pass.txt
      n
    

Note: when project_directory/terraform/ansible.cfg is commented out, ansible uses ~/.ansible.cfg and is able to decrypt encrypted files.

EXPECTED RESULTS

I expect playbook to decrypt all encrypted vars using the ansible vault password saved in the path provide in the configuration file (ansible.cfg) provided in the project directory.

ACTUAL RESULTS

I get the error below:

Error: Error applying plan:

1 error(s) occurred:

* linode_linode.base: Error running command 'sleep 30; ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --ask-pass -i '172.104.29.185,' ../ansible/provision.yml --extra-vars 'ip=000.111.22.185' -vvvv': exit status 5. Output: Error reading config file (/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg): File contains no section headers.
file: '/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg', line: 3
'vault_password_file = ~/.vault_pass.txt\n'

Can someone please explain why I keep getting the error **exit status 5. Output: Error reading config file (/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg): File contains no section headers.

  • I also tried looking for info on how ansible generates the default /etc/ansible.cfg file but can't seem to track it down (I use python in a limited capacity so this might be why I am having a hard time with this)

Would really appreciate it.

1 Answers

ansible.cfg is supposed to be divided into sections with headers of the form [section_name]. The vault_password_file option, like the majority of the configuration options, belongs to the [defaults] section, so your ansible.cfg needs to look like:

[defaults]
vault_password_file = ~/.vault_pass.txt
Related