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

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”

]

}

}

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

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

  > uname -a
  FreeBSD <sanitized> 12.1-RELEASE FreeBSD 12.1-RELEASE r354233 GENERIC amd64
  
  > cat hosts
  test1 ansible_host=10-1
  test2 ansible_host="10-1"
  
  > 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"
          ]
      }
  }
  
  > ansible-inventory-3.6 -i hosts --list
  {
      "_meta": {
          "hostvars": {
              "test1": {
                  "ansible_host": 9
              },
              "test2": {
                  "ansible_host": 9
              }
          }
      },
      "all": {
          "children": [
              "ungrouped"
          ]
      },
      "ungrouped": {
          "hosts": [
              "test1",
              "test2"
          ]
      }
  }

Reported to the AWX project: https://github.com/ansible/awx/issues/7448

Reason for the behaviour with python 3.6: https://github.com/ansible/ansible/issues/70323#issuecomment-650176138

many thanks to @ryanpetrello

Regards
CWollinger