# Error reading config file (/etc/ansible/ansible.cfg): Source contains parsing errors: '\<string\>' \[line 4\]: ' 3 \\n' #601

**URL:** <https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786>\
**Category:** Ansible Project\
**Created:** [March 15, 2021, 7:53pm UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786 "2021-03-15T19:53:13Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohamed\_Rahiman](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mohamed\_Rahiman](https://forum.ansible.com/u/Mohamed_Rahiman)\
**Post date:** [March 15, 2021, 7:53pm UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/1 "2021-03-15T19:53:13Z")

</div>

Error reading config file (/etc/ansible/ansible.cfg): Source contains parsing errors: ‘’ [line 4]: ’ 3 \n’ #601

Hi Guys

I am learning Ansible as a newbie so that i can get into the industry of IT, I am learning everything from scratch  
I have two hosts - hosts 1 and 2  
i am trying to create a file from host 1 to host 2 - using ansible when i do this i get the following

Error reading config file (/etc/ansible/ansible.cfg): Source contains parsing errors: ‘’  
[line 4]: ’ 3 \n’  
[line 5]: ’ 4 # nearly all parameters can be overridden in ansible-playbook\n’  
[line 6]: ’ 5 # or with command line flags. ansible will read ANSIBLE\_CONFIG,\n’  
[line 7]: ’ 6 # ansible.cfg in the current working directory, .ansible.cfg in\n’  
[line 8]: ’ 7 # the home directory or /etc/ansible/ansible.cfg, whichever it\n’  
[line 9]: ’ 8 # finds first\n’

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [March 15, 2021, 8:14pm UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/2 "2021-03-15T20:14:56Z")

</div>

Do you really have line numbers in your config file?

You should watch out for line endings, as well - make sure you create these  
files using Linux, don't do it on a Windows machine and copy them across...

Antony.

---

<div class="post-metadata">

**Author:** ![Mohamed\_Rahiman](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mohamed\_Rahiman](https://forum.ansible.com/u/Mohamed_Rahiman)\
**Post date:** [March 16, 2021, 10:34am UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/3 "2021-03-16T10:34:13Z")

</div>

Hi Guys sorry new to this and thanks to Antony Stone - sorry if im being dents but im determined to learn this and glad i found such a great group

so actually i did have the lines and took them out - now i am getting the following

[WARNING]: \* Failed to parse /etc/ansible/hosts with yaml plugin: YAML  
inventory has invalid structure, it should be a dictionary, got: \<class  
‘ansible.parsing.yaml.objects.AnsibleUnicode’\>  
[WARNING]: \* Failed to parse /etc/ansible/hosts with ini plugin:  
/etc/ansible/hosts:1: Expected key=value host variable assignment, got:  
ubuntu2004  
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source  
[WARNING]: No inventory was parsed, only implicit localhost is available  
[WARNING]: provided hosts list is empty, only localhost is available. Note that  
the implicit localhost does not match ‘all’

[WARNING]: Could not match supplied host pattern, ignoring: ubuntu2004\*

Basically all i am trying to do is the following - im going through th basics

[root@sc-centos-1-2-1-build-1 ansible]# ansible ubuntu2004\* -m file -a “path=/home/user1/file2.txt state=touch mode=700”

---

<div class="post-metadata">

**Author:** ![Mohamed\_Rahiman](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mohamed\_Rahiman](https://forum.ansible.com/u/Mohamed_Rahiman)\
**Post date:** [March 16, 2021, 11:06am UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/4 "2021-03-16T11:06:35Z")

</div>

ok guys did a bit of rtfm and my format for the hosts file was in no format so i did the yaml format with colons and begnnining with all:  
however no i get this

[root@sc-centos-1-2-1-build-1 ansible]# ansible ubuntu2004\* -m file -a “path=/home/user1/file2.txt state=touch mode=700”  
[WARNING]: Could not match supplied host pattern, ignoring: ubuntu2004\*  
[WARNING]: No hosts matched, nothing to do  
[root@sc-centos-1-2-1-build-1 ansible]#

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [March 16, 2021, 11:13am UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/5 "2021-03-16T11:13:08Z")

</div>

Instead of creating your own playbooks in a format you're not familiar with,  
have you tried starting from a worked-example tutorial which guides you  
through creating simple playbooks and getting used to ansible commands and  
YAML formatting?

For example:

[https://docs.ansible.com/ansible/latest/network/getting\_started/first\_playbook.html](https://docs.ansible.com/ansible/latest/network/getting_started/first_playbook.html)

[https://docs.ansible.com/ansible/latest/user\_guide/intro\_getting\_started.html](https://docs.ansible.com/ansible/latest/user_guide/intro_getting_started.html)

[https://www.ansible.com/resources/get-started](https://www.ansible.com/resources/get-started)

Antony.

---

<div class="post-metadata">

**Author:** ![Mohamed\_Rahiman](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mohamed\_Rahiman](https://forum.ansible.com/u/Mohamed_Rahiman)\
**Post date:** [March 16, 2021, 3:50pm UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/6 "2021-03-16T15:50:31Z")

</div>

thanks Antony

I think these docs are a good start , created the ssh key pair as i was getting a permission denied  
trying it out this first command below  
what is -m vyos.vyos.vyos\_facts -e and ansible\_network\_os=vyos.vyos.vyos

```auto
ansible all -i [vyos.example.net](http://vyos.example.net), -c ansible.netcommon.network_cli -u my_vyos_user -k -m vyos.vyos.vyos_facts -e ansible_network_os=vyos.vyos.vyos

```

---

<div class="post-metadata">

**Author:** ![Mohamed\_Rahiman](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mohamed\_Rahiman](https://forum.ansible.com/u/Mohamed_Rahiman)\
**Post date:** [March 16, 2021, 7:20pm UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/7 "2021-03-16T19:20:43Z")

</div>

ok getting the hang of it - but i have added the ssh keys from master to client  
but when i run ansible -m ping all

i get the following  
root@ubuntu2004:/home/ubuntu# sudo ansible -m ping linux 192.168.1.115 | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: [root@192.168.1.115](mailto:root@192.168.1.115): Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).”,  
“unreachable”: true  
}  
root@ubuntu2004:/home/ubuntu#

---

<div class="post-metadata">

**Author:** ![Emiliano\_Vazquez](https://avatars.discourse-cdn.com/v4/letter/e/df705f/32.png) [@Emiliano\_Vazquez](https://forum.ansible.com/u/Emiliano_Vazquez)\
**Post date:** [March 17, 2021, 1:57pm UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/8 "2021-03-17T13:57:13Z")

</div>

> “msg”: “Failed to connect to the host via ssh: [root@192.168.1.115](mailto:root@192.168.1.115): Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).”,  
> “unreachable”: true

please first try to connect over ssh without asking password

On your host running ansible try this:

**_ssh [root@192.168.1.115](mailto:root@192.168.1.115)_**

You need to enter this host without any password  
If you fail take a look at this link [https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-debian-10](https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-debian-10) or another talking about this theme.

Best regards.

---

<div class="post-metadata">

**Author:** ![Mohamed\_Rahiman](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mohamed\_Rahiman](https://forum.ansible.com/u/Mohamed_Rahiman)\
**Post date:** [March 18, 2021, 9:56am UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/9 "2021-03-18T09:56:08Z")

</div>

thanks Anthony

---

<div class="post-metadata">

**Author:** ![omodotun\_Babatope](https://avatars.discourse-cdn.com/v4/letter/o/58956e/32.png) [@omodotun\_Babatope](https://forum.ansible.com/u/omodotun_Babatope)\
**Post date:** [March 28, 2022, 11:09am UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/10 "2022-03-28T11:09:08Z")

</div>

Hello Anthony,

Greetings to you.

Hope my email finds you well.

I am trying to connect to my linux ubuntu and centOS VM using this IP: 13.67.227.239 & 13.89.200.76  
I have this error: (/home/ansible/tutorials/chapter1/ansible.cfg): Source contains parsing errors: ‘’  
[line 2]: ‘13.67.227.239\n’  
[line 4]: ‘13.89.200.76\n’

Can you please advise.

I would be happpy to get a response from you.

Best regards.  
Dotun.

---

<div class="post-metadata">

**Author:** ![Zhen\_Zeng](https://avatars.discourse-cdn.com/v4/letter/z/9de0a6/32.png) [@Zhen\_Zeng](https://forum.ansible.com/u/Zhen_Zeng)\
**Post date:** [November 14, 2023, 1:06am UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/11 "2023-11-14T01:06:16Z")

</div>

Hi Omodotun,  
I think that’s because your Ansible config file is too old.  
It’s old format.

You should use new syntax in the config file.  
Here is my example

ansible.cfg

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [November 14, 2023, 12:38pm UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/12 "2023-11-14T12:38:48Z")

</div>

You seem to have added inventory to the ansible configuration file, instead of to the inventory.  
Start out with an empty configuration, and add your hosts to the inventory file.  
As this is fundamental to doing anything with ansible, you may want to read [https://docs.ansible.com/ansible/latest/getting\_started/index.html](https://docs.ansible.com/ansible/latest/getting_started/index.html)

DIck

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 14, 2023, 3:48pm UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/13 "2023-11-14T15:48:26Z")

</div>

> I think that's because your Ansible config file is too old.  
> It's old format.

The ansible.cfg file format has not changed since 0.4, new options  
have been added but the format has always been the same.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 14, 2023, 3:49pm UTC](https://forum.ansible.com/t/error-reading-config-file-etc-ansible-ansible-cfg-source-contains-parsing-errors-string-line-4-3-n-601/34786/14 "2023-11-14T15:49:36Z")

</div>

You can use `ansible-config` both to verify the file and to generate one.
