RE: [ansible-project] Can’t use dash with numbers as hostname

256 views
Skip to first unread message

Stuart Lowe

unread,
Jun 25, 2020, 11:35:48 AM6/25/20
to ansible...@googlegroups.com

I’m not getting the same thing happen.

The ansible_host var is expecting a fqdn or ip so should just show like below.
what version of ansible are you using?

 

# cat test

test1 ansible_host=10-1

test2 ansible_host="10-1"

test3 ansible_host='10-1'

 

 

ansible-inventory -i test --list

{

    "_meta": {

        "hostvars": {

            "test1": {

                "ansible_host": "10-1"

            },

            "test2": {

                "ansible_host": "10-1"

            },

            "test3": {

                "ansible_host": "10-1"

            }

        }

    },

    "all": {

        "children": [

            "ungrouped"

        ]

    },

    "ungrouped": {

        "hosts": [

            "test1",

            "test2",

            "test3"

        ]

    }

}

 

From: ansible...@googlegroups.com <ansible...@googlegroups.com> On Behalf Of CWollinger
Sent: 25 June 2020 15:57
To: Ansible Project <ansible...@googlegroups.com>
Subject: [ansible-project] Cant use dash with numbers as hostname

 

Hi all,

is there a way to escape the dash/minus in the hostname (when using numbers)

hostfile:

test1 ansible_host=10-1
test2 ansible_host="10-1"

Result:

bash-4.4# ansible-inventory -i hosts --list
{
    "_meta": {
        "hostvars": {
            "test1": {
                "ansible_host": 9
            },
            "test2": {
                "ansible_host": 9
            }
        }
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    },
    "ungrouped": {
        "hosts": [
            "test1",
            "test2"
        ]
    }
}

The ansible-inventory made a calculation for the var ....

Thanks & regards
CWollinger

--
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/0061cc9d-d2f2-43f4-8f70-ad60c720b5ado%40googlegroups.com.

--
Stuart Lowe
Cloud & Hosting Engineer
Zen Internet
Team: 01706 902009
Web: zen.co.uk

Winner of 'Services Company of the Year' at the UK IT Industry Awards

This message is private and confidential. If you have received this message in error, please notify us and remove it from your system.


Zen Internet Limited may monitor email traffic data to manage billing, to handle customer enquiries and for the prevention and detection of fraud. We may also monitor the content of emails sent to and/or from Zen Internet Limited for the purposes of security, staff training and to monitor quality of service.

Zen Internet Limited is registered in England and Wales, Sandbrook Park, Sandbrook Way, Rochdale, OL11 1RY Company No. 03101568 VAT Reg No. 686 0495 01

CWollinger

unread,
Jun 26, 2020, 2:33:20 AM6/26/20
to Ansible Project
I think the python version is the problem here.
I see the behavior with ansible using python 3.6.x on a host system or in the current awx container (12.0.0 or 13.0.0). AWX uses python 3.6 currently.
When I use ansible with Python 3.8.x, I see the correct result like you described.

Regards
CWollinger

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

Vladimir Botka

unread,
Jun 26, 2020, 3:03:16 AM6/26/20
to CWollinger, ansible...@googlegroups.com
On Thu, 25 Jun 2020 23:33:20 -0700 (PDT)
CWollinger <cwolli...@gmail.com> wrote:

> I think the python version is the problem here.
> I see the behavior with ansible using python 3.6.x

You're probably right. I see the problem in FreeBSD too


shell> uname -a
FreeBSD <sanitized> 12.1-RELEASE FreeBSD 12.1-RELEASE r354233 GENERIC amd64

shell> cat hosts
test1 ansible_host=10-1
test2 ansible_host="10-1"

shell> ansible-inventory-2.7 -i hosts --list
{
"_meta": {
"hostvars": {
"test1": {
"ansible_host": "10-1"
},
"test2": {
"ansible_host": "10-1"
}
}
},
"all": {
"children": [
"ungrouped"
]
},
"ungrouped": {
"hosts": [
"test1",
"test2"
]
}
}

shell> ansible-inventory-3.6 -i hosts --list
{
"_meta": {
"hostvars": {
"test1": {
"ansible_host": 9
},
"test2": {
"ansible_host": 9
}
}
},
"all": {
"children": [
"ungrouped"
]
},
"ungrouped": {
"hosts": [
"test1",
"test2"
]
}
}

--
Vladimir Botka

CWollinger

unread,
Jun 26, 2020, 11:03:12 AM6/26/20
to Ansible Project
Reported to the AWX project: https://github.com/ansible/awx/issues/7448


many thanks to @ryanpetrello

Regards
CWollinger
Reply all
Reply to author
Forward
0 new messages