Ошибка file contains no section headers

I keep getting this error everytime i use yum :

yum install unison240
Loaded plugins: fastestmirror, priorities, refresh-packagekit, security
Error: File contains no section headers.
file: file://///etc/yum.repos.d/CentOS-Base.repo, line: 12
'priority=1n'

I am very new to this world (A small month) and didnt use it very much yet because i just started engineering school.

It seems as if CentOs-Base.repo had an error in it and i actually tried to create priorities.sh in order to follow this tutorial from my school : https://ensiwiki.ensimag.fr/index.php/Portail:Centos which could have done the error.

(First Section named «Depots Centos 6.5»)

I dont know if it helps you.

This error happens with every use of yum. Here, I was just trying to get Unison from the package epel that i already got on my computer.

Thank you for your help!

asked Oct 16, 2014 at 14:40

Fitz's user avatar

FitzFitz

3271 gold badge6 silver badges19 bronze badges

6

Looks like your /etc/yum.repos.d/CentOS-Base.repo is broken — have missing [CentOS-Base] stanza. I was able to recreate the situation using:

# cat /etc/yum.repos.d/kzak-mytt-kz.repo 
[kzak-mutt-kz]
name=Copr repo for mutt-kz owned by kzak
baseurl=http://copr-be.cloud.fedoraproject.org/results/kzak/mutt-kz/fedora-$releasever-$basearch/
skip_if_unavailable=True
gpgcheck=0
enabled=1
# yum repolist
<works as expected>
# gedit /etc/yum.repos.d/kzak-mytt-kz.repo   # now I have removed first line
# cat /etc/yum.repos.d/kzak-mytt-kz.repo 
name=Copr repo for mutt-kz owned by kzak
baseurl=http://copr-be.cloud.fedoraproject.org/results/kzak/mutt-kz/fedora-$releasever-$basearch/
skip_if_unavailable=True
gpgcheck=0
enabled=1
# yum repolist
Loaded plugins: etckeeper
File contains no section headers.
file: file:///etc/yum.repos.d/kzak-mytt-kz.repo, line: 1
'name=Copr repo for mutt-kz owned by kzakn'

So fix would be to go into /etc/yum.repos.d/CentOS-Base.repo and fix syntax of the file.

answered Oct 31, 2014 at 22:53

jhutar's user avatar

jhutarjhutar

1,3592 gold badges17 silver badges32 bronze badges

1

The header section of one of your mirrors in that repo is missing. It is a name inside Brackets []. You can add it yourself.

In terminal, type:

nano /etc/yum.repos.d/CentOS-Base.repo

Then go to the line 12 and add a section header like [Name] ABOVE the line beginning with «name»

Assuming the header section is called «update», it should look like:

[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

answered Jun 7, 2018 at 7:46

Feri's user avatar

FeriFeri

2304 silver badges11 bronze badges

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 read ansible.cfg file

ISSUE TYPE
  • Bug Report
COMPONENT NAME

I am not sure but I think it has to be with the Ini Config Parser

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
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.txtn'
OS / ENVIRONMENT

macOS High Sierra

STEPS TO REPRODUCE

directory layout:

- project_dir
  - terraform 
    - ansible.cfg
    - base.tf 
    - terraform.tfvars
    - variables.tfvars
  - ansible 
    - roles 
      - user 
        - tasks
          - main.yml
        - vars
          - creds.yml
    - provison.yml

Note: Within role dir, have a task that makes sure of an encrypted file (roles/user/vars/creds.yml)

  • 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

Running terraform (terraform init && terraform apply ends up calling ansible via local-exec

`  provisioner "local-exec" {
    command = "sleep 30; ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --ask-pass -i '${linode_linode.base.ip_address},' ../ansible/provision.yml --extra-vars 'ip=${linode_linode.base.ip_address}' -vvvv"
  }
`

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:

terraform init && terraform apply

Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "null" (1.0.0)...
- Downloading plugin for provider "template" (1.0.0)...


Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
 <= read (data resources)

Terraform will perform the following actions:

 <= data.template_file.hosts
      id:                              <computed>
      rendered:                        <computed>
      template:                        "[public]n${api_public}n"
      vars.%:                          <computed>

  + linode_linode.base
      id:                              <computed>
      disk_expansion:                  "false"
      group:                           "Test-group"
      helper_distro:                   "true"
      image:                           "Ubuntu 16.04 LTS"
      ip_address:                      <computed>
      kernel:                          "Latest 64 bit"
      manage_private_ip_automatically: "true"
      name:                            "Test"
      plan_storage:                    <computed>
      plan_storage_utilized:           <computed>
      private_ip_address:              <computed>
      region:                          "Newark, NJ, USA"
      root_password:                   "QLWOVauEwNxWGbj2ErWF9vFYIXsxW/2duL/og8gtV84="
      size:                            "1024"
      ssh_key:                         "Gb4DfTd6icrN49GevRjx+9IwmSgVVCLU8WjL0PY2p0s="
      status:                          <computed>
      swap_size:                       "512"

  + null_resource.hosts
      id:                              <computed>
      triggers.%:                      <computed>


Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

linode_linode.base: Creating...
  disk_expansion:                  "" => "false"
  group:                           "" => "Test-group"
  helper_distro:                   "" => "true"
  image:                           "" => "Ubuntu 16.04 LTS"
  ip_address:                      "" => "<computed>"
  kernel:                          "" => "Latest 64 bit"
  manage_private_ip_automatically: "" => "true"
  name:                            "" => "Test"
  plan_storage:                    "" => "<computed>"
  plan_storage_utilized:           "" => "<computed>"
  private_ip_address:              "" => "<computed>"
  region:                          "" => "Newark, NJ, USA"
  root_password:                   "" => "QLWOVauEwNxWGbj2ErWF9vFYIXsxW/2duL/og8gtV84="
  size:                            "" => "1024"
  ssh_key:                         "" => "Gb4DfTd6icrN49GevRjx+9IwmSgVVCLU8WjL0PY2p0s="
  status:                          "" => "<computed>"
  swap_size:                       "" => "512"
linode_linode.base: Still creating... (10s elapsed)
linode_linode.base: Still creating... (20s elapsed)
linode_linode.base: Still creating... (30s elapsed)
linode_linode.base: Still creating... (40s elapsed)
linode_linode.base: Still creating... (50s elapsed)
linode_linode.base: Provisioning with 'remote-exec'...
linode_linode.base (remote-exec): Connecting to remote host via SSH...
linode_linode.base (remote-exec):   Host: 172.104.29.185
linode_linode.base (remote-exec):   User: root
linode_linode.base (remote-exec):   Password: true
linode_linode.base (remote-exec):   Private key: false
linode_linode.base (remote-exec):   SSH Agent: true
linode_linode.base (remote-exec):   Checking Host Key: false
linode_linode.base: Still creating... (1m0s elapsed)
linode_linode.base (remote-exec): Connecting to remote host via SSH...
linode_linode.base (remote-exec):   Host: 172.104.29.185
linode_linode.base (remote-exec):   User: root
linode_linode.base (remote-exec):   Password: true
linode_linode.base (remote-exec):   Private key: false
linode_linode.base (remote-exec):   SSH Agent: true
linode_linode.base (remote-exec):   Checking Host Key: false
linode_linode.base (remote-exec): Connected!
linode_linode.base (remote-exec): foo
linode_linode.base: Provisioning with 'local-exec'...
linode_linode.base (local-exec): Executing: ["/bin/sh" "-c" "sleep 30; ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --ask-pass -i '172.104.29.185,' ../ansible/provision.yml --extra-vars 'ip=172.104.29.185' -vvvv"]
linode_linode.base: Still creating... (1m10s elapsed)
linode_linode.base: Still creating... (1m20s elapsed)
linode_linode.base: Still creating... (1m30s elapsed)
linode_linode.base (local-exec): Error reading config file (/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg): File contains no section headers.
linode_linode.base (local-exec): file: '/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg', line: 3
linode_linode.base (local-exec): 'vault_password_file = ~/.vault_pass.txtn'

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=172.104.29.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.txtn'


Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

The «MissingSectionHeaderError: File contains no section headers» error is raised in Python when using the configparser module and trying to read a configuration file that doesn’t have any section headers defined. Section headers are defined using square brackets ([]) and are used to delimit different sections of the configuration file. Each section can have its own key-value pairs, which can be accessed using the configparser module. If a configuration file doesn’t have any section headers defined, the configparser module won’t be able to parse the file, and will raise the «MissingSectionHeaderError: File contains no section headers» error.

To fix the MissingSectionHeaderError error in Python, you can add section headers to the configuration file. Here are the steps to do so:

  1. Import the ConfigParser module:
  1. Create an instance of the ConfigParser class:
config = configparser.ConfigParser()
  1. Read the configuration file:
config.read('config.ini')
  1. Add a section header to the configuration file:
config['section_name'] = {}
  1. Add options to the section:
config['section_name']['option_name'] = 'option_value'
  1. Write the changes back to the configuration file:
with open('config.ini', 'w') as configfile:
    config.write(configfile)

Here is an example configuration file with a missing section header:

option1 = value1
option2 = value2

To add a section header to this configuration file, you can use the following code:

import configparser

config = configparser.ConfigParser()
config.read('config.ini')

config['section_name'] = {}
config['section_name']['option1'] = 'value1'
config['section_name']['option2'] = 'value2'

with open('config.ini', 'w') as configfile:
    config.write(configfile)

This will add a section header called [section_name] to the configuration file and move the option1 and option2 options under that section header.

Method 2: Using a Different Parsing Library

If you encounter the error «MissingSectionHeaderError: File contains no section headers» while working with Python’s built-in ConfigParser library, you can try using a different parsing library to solve the issue. Here’s how you can do it step by step:

  1. Install the configobj library:
  1. Import the configobj library:
  1. Load the configuration file using the configobj library:
config = configobj.ConfigObj('config_file.ini')
  1. Access the values in the configuration file as you normally would with the ConfigParser library:
value = config.get('section_name', 'key_name')

Here’s an example code snippet that demonstrates how to use configobj to access the value of a key in a configuration file:

import configobj

config = configobj.ConfigObj('config_file.ini')
value = config.get('database', 'password')
print(value)

In this example, we’re accessing the value of the password key in the database section of the config_file.ini configuration file.

Using a different parsing library like configobj can be a simple and effective solution to fix the «MissingSectionHeaderError: File contains no section headers» error in Python.

Method 3: Reading the Configuration File as Raw Text

To fix the «MissingSectionHeaderError: File contains no section headers» error in Python when reading a configuration file, you can use the following steps:

  1. Open the configuration file using the built-in Python open() function and read its contents as raw text.
with open('config.ini') as f:
    config_raw = f.read()
  1. Split the raw text into lines using the splitlines() method.
config_lines = config_raw.splitlines()
  1. Add a dummy section header to the beginning of the lines list.
config_lines.insert(0, '[dummy_section]')
  1. Join the lines back into a single string using the join() method.
config_fixed = 'n'.join(config_lines)
  1. Use the configparser module to parse the fixed configuration string.
import configparser

config = configparser.ConfigParser()
config.read_string(config_fixed)

Here is the full code example:

import configparser

with open('config.ini') as f:
    config_raw = f.read()

config_lines = config_raw.splitlines()
config_lines.insert(0, '[dummy_section]')
config_fixed = 'n'.join(config_lines)

config = configparser.ConfigParser()
config.read_string(config_fixed)

This code reads the config.ini file as raw text, adds a dummy section header to the beginning of the lines list, joins the lines back into a single string, and finally parses the fixed configuration string using the configparser module. This should fix the «MissingSectionHeaderError: File contains no section headers» error.

I’m working on setting up Fail2ban for my linux (debian) server. When I check the status of the fail2ban service I am getting this error:

● fail2ban.service - Fail2Ban Service
   Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2020-11-01 13:15:05 EST; 5s ago
     Docs: man:fail2ban(1)
  Process: 17851 ExecStartPre=/bin/mkdir -p /var/run/fail2ban (code=exited, status=0/SUCCESS)
  Process: 17852 ExecStart=/usr/bin/fail2ban-server -xf start (code=exited, status=255/EXCEPTION)
 Main PID: 17852 (code=exited, status=255/EXCEPTION)

Nov 01 13:15:05 raspberrypi systemd[1]: Starting Fail2Ban Service...
Nov 01 13:15:05 raspberrypi systemd[1]: Started Fail2Ban Service.
Nov 01 13:15:05 raspberrypi fail2ban-server[17852]:  Failed during configuration: File contains no section headers.
Nov 01 13:15:05 raspberrypi fail2ban-server[17852]: file: '/etc/fail2ban/jail.local', line: 21
Nov 01 13:15:05 raspberrypi fail2ban-server[17852]: 'bantime = 1hn'
Nov 01 13:15:05 raspberrypi fail2ban-server[17852]:  Async configuration of server failed
Nov 01 13:15:05 raspberrypi systemd[1]: fail2ban.service: Main process exited, code=exited, status=255/EXCEPTION
Nov 01 13:15:05 raspberrypi systemd[1]: fail2ban.service: Failed with result 'exit-code'.

I have a feeling this has something to do with my config file, here is the first 30 lines of it:

#
# WARNING: heavily refactored in 0.9.0 release.  Please review and
#          customize settings for your setup.
#
# Changes:  in most of the cases you should not modify this
#           file, but provide customizations in jail.local file,
#           or separate .conf files under jail.d/ directory, e.g.:
#
# HOW TO ACTIVATE JAILS:
#
# YOU SHOULD NOT MODIFY THIS FILE.
#
# It will probably be overwritten or improved in a distribution update.
#
# Provide customizations in a jail.local file or a jail.d/customisation.local.
# For example to change the default bantime for all jails and to enable the
# ssh-iptables jail the following (uncommented) would appear in the .local file.
# See man 5 jail.conf for details.
#
# [DEFAULT]
bantime = 1h
#
# [sshd]
enabled = true
#
# See jail.conf(5) man page for more information



# Comments: use '#' for comment lines and ';' (following a space) for inline comments


[INCLUDES]

#before = paths-distro.conf
before = paths-debian.conf

# The DEFAULT allows a global definition of the options. They can be overridden
# in each jail afterwards.

[DEFAULT]

#
# MISCELLANEOUS OPTIONS
#

asked Nov 1, 2020 at 18:22

x43's user avatar

For the case still actual or someone would find it later.

Firstly, don’t copy jail.conf into jail.local, use empty one.

Then, this is wrong:

# [sshd]
enabled = true

Before enabled is no section in your file (lines started with # are comments).

This would be correct jail.local file:

[DEFAULT]
# here you can overwrite some defaults:

[sshd]
enabled = true

[other-jail]
enabled = true

...

answered Dec 19, 2020 at 23:10

sebres's user avatar

sebressebres

3211 silver badge6 bronze badges

When I tried to install CMake but writing the following

sudo yum install cmake

I got the following error

File contains no section headers.
file: file:///etc/yum.repos.d/mcepl-vim8-epel-7.repo, line: 2
'<!doctype html>n

asked Feb 27, 2019 at 10:53

Salem Masoud's user avatar

3

I solve by

rm /etc/yum.repos.d/mcepl-vim8-epel-7.repo

answered May 27, 2019 at 14:33

Salem Masoud's user avatar

As a safer solution, it’s just enough to rename that repo file:

# cd /etc/yum.repos.d/
# mv <repo_file>.repo <repo_file>.repo.orig

answered May 16, 2022 at 4:10

Omid Estaji's user avatar

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

Понравилась статья? Поделить с друзьями:
  • Ошибка file boot bcd 0xc00000e9 windows 10
  • Ошибка fmt001305 неверный mime тип шаблонами
  • Ошибка file altlinux main pkglist file not found
  • Ошибка fmodex dll что делать
  • Ошибка file access denied for