Invalid characters were found in group names but not replaced ansible k8s

Viewed 10172

My k8s.yaml inventory file is:

plugin: k8s

connections:

- kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml'

context: 'user1@testeks.us-east-1.eksctl.io'

ansible playbook:

test_new.yml

- hosts: localhost

tasks:

- name: Create a k8s namespace

k8s:

name: testing3

api_version: v1

kind: Namespace

state: present

Looks like the ansibleplaybook command is not picking up the inventory k8s.yaml.Also I am not sure why I am getting Warning invalid characters {'-' in group name warnings.

Please let me know if the above inventory file and ansible playbook files look good or are there anything I am missing?

ansible-playbook -vvvv -i k8s.yaml -vvv ./test_new.yml
No config file found; using defaults

setting up inventory plugins

host_list declined parsing /Users/user1/Documents/Learning/ansible/k8s.yaml as it did not pass its verify_file() method

script declined parsing /Users/user1/Documents/Learning/ansible/k8s.yaml as it did not pass its verify_file() method

Not replacing invalid character(s) "{'-', '9'}" in group name (909676E2B4F81625BF5994625D3353C9-yl4-us-east-1-eks-amazonaws-com)

[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

Not replacing invalid character(s) "{'-'}" in group name (namespace_add-ons)

Not replacing invalid character(s) "{'-'}" in group name (namespace_add-ons_pods)

Not replacing invalid character(s) "{'.', '/', '-'}" in group name (label_app.kubernetes.io/instance_aws-cluster-autoscaler)
2 Answers

I'm not sure where you got that you need the Kubernetes parameters specified in your inventory file. If you look at the k8s module documentation it says that kubeconfig and context are specified in the playbook or as environment variables.

Your inventory should look something like this:

all:
  hosts:
    host.where.can.access.the.kubeapiserver.com:

Then your playbook:

- name: Create a k8s namespace
  k8s:
    name: testing3
    api_version: v1
    kind: Namespace
    state: present
    kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml'  this can replaced by the K8S_AUTH_KUBECONFIG env variable
    context: 'user1@testeks.us-east-1.eksctl.io'   this can replaced by the K8S_AUTH_CONTEXT env variable

Based on the formatting of your post, it looks like your inventory file contains improper syntax. It should look like this:

plugin: k8s
connections:
  - kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml'
    context: 'user1@testeks.us-east-1.eksctl.io'

Remember that spaces are important.

For deprecation warnings, be sure to read up on these issues:
https://github.com/ansible/ansible/issues/56930
https://github.com/kubernetes-sigs/kubespray/issues/4830

Usage of hyphens in inventory group names was deprecated in Ansible 2.8 due to Python parser errors when using dot syntax. Auto-transformation can be disabled by adding force_valid_group_names = never to your Ansible config file. Similarly, deprecation warnings can be suppressed by adding deprecation_warnings = False though this is not recommended.

Related