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

1,466 views
Skip to first unread message

Mohamed Rahiman

unread,
Mar 15, 2021, 3:53:13 PM3/15/21
to Ansible Project

Error reading config file (/etc/ansible/ansible.cfg): Source contains parsing errors: '<string>' [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'

Antony Stone

unread,
Mar 15, 2021, 4:15:48 PM3/15/21
to ansible...@googlegroups.com
On Monday 15 March 2021 at 20:53:13, Mohamed Rahiman wrote:

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

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.

--
"It is easy to be blinded to the essential uselessness of them by the sense of
achievement you get from getting them to work at all. In other words - and
this is the rock solid principle on which the whole of the Corporation's
Galaxy-wide success is founded - their fundamental design flaws are completely
hidden by their superficial design flaws."

- Douglas Noel Adams

Please reply to the list;
please *don't* CC me.

Mohamed Rahiman

unread,
Mar 16, 2021, 6:34:38 AM3/16/21
to ansible...@googlegroups.com
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"

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6399a87a-5473-4acc-a974-c339eb458e0fn%40googlegroups.com.

Mohamed Rahiman

unread,
Mar 16, 2021, 7:07:00 AM3/16/21
to ansible...@googlegroups.com
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]#

Antony Stone

unread,
Mar 16, 2021, 7:13:33 AM3/16/21
to ansible...@googlegroups.com
On Tuesday 16 March 2021 at 12:06:35, Mohamed Rahiman wrote:

> 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

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/user_guide/intro_getting_started.html

https://www.ansible.com/resources/get-started


Antony.

--
"640 kilobytes (of RAM) should be enough for anybody."

- Bill Gates

Mohamed Rahiman

unread,
Mar 16, 2021, 11:50:59 AM3/16/21
to ansible...@googlegroups.com
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

ansible all -i 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

Mohamed Rahiman

unread,
Mar 16, 2021, 3:21:07 PM3/16/21
to ansible...@googlegroups.com
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: ro...@192.168.1.115: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
    "unreachable": true
}
root@ubuntu2004:/home/ubuntu#
 

Emiliano Vazquez

unread,
Mar 17, 2021, 9:57:36 AM3/17/21
to ansible...@googlegroups.com

    "msg": "Failed to connect to the host via ssh: ro...@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:





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 or another talking about this theme.

Best regards.



Mohamed Rahiman

unread,
Mar 18, 2021, 5:56:32 AM3/18/21
to ansible...@googlegroups.com
thanks Anthony

On Tue, 16 Mar 2021 at 11:13, Antony Stone <Antony...@ansible.open.source.it> wrote:

omodotun Babatope

unread,
Mar 28, 2022, 7:09:09 AM3/28/22
to Ansible Project
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: '<string>'
        [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.



To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.

Zhen Zeng

unread,
Nov 13, 2023, 11:01:06 PM11/13/23
to Ansible Project
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
=====
[defaults]
inventory = ./inventory
private_key_file = ~/.ssh/id_rsa.field.private
=====

inventory file :
=====
[cdp]
zzeng01.novalocal
zzeng02.novalocal
zzeng03.novalocal
zzeng04.novalocal
=====

Then 
[centos@zzeng01 ~]$ ansible cdp -m ping
zzeng02.novalocal | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
zzeng04.novalocal | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
zzeng03.novalocal | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
zzeng01.novalocal | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}


2022年3月28日月曜日 20:09:09 UTC+9 omodotun Babatope:
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Dick Visser

unread,
Nov 14, 2023, 7:39:22 AM11/14/23
to ansible...@googlegroups.com
On Mon, 28 Mar 2022 at 13:09, omodotun Babatope <babato...@gmail.com> wrote:
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: '<string>'
        [line  2]: '13.67.227.239\n'
        [line  4]: '13.89.200.76\n'

Can you please advise.


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

DIck

Brian Coca

unread,
Nov 14, 2023, 10:48:51 AM11/14/23
to ansible...@googlegroups.com
>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.
--
----------
Brian Coca

Brian Coca

unread,
Nov 14, 2023, 10:50:04 AM11/14/23
to ansible...@googlegroups.com
You can use `ansible-config` both to verify the file and to generate one.


--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages