Skip to content

"make run" fails for scaffolded Ansible operator with roles #4071

@dalbani

Description

@dalbani

Bug Report

What did you do?

I created a very simple Ansible operator with steps like:

$ operator-sdk init --project-version=3-alpha --project-name thing-operator --domain domain.com --plugins ansible
$ operator-sdk create api --group things --version v1alpha1 --kind Thing --generate-playbook --generate-role
$ kubectl apply -f config/crd/bases/things.domain.com_things.yaml
$ kubectl apply -f config/samples/things_v1alpha1_thing.yaml

Note that I specified --generate-role.

What did you expect to see?

I expected the make run command to work out of the box.

What did you see instead? Under which circumstances?

This is the error message that I got:

$ make run
...
ERROR! the role 'thing' was not found in community.kubernetes:operator_sdk.util:ansible.legacy:/home/damianoa/work/thing-operator/playbooks/roles:/home/damianoa/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/damianoa/work/thing-operator/playbooks
...

Environment

Operator type:

/language ansible

Kubernetes cluster type:

Minikube

$ operator-sdk version

operator-sdk version: "v1.1.0", commit: "9d27e224efac78fcc9354ece4e43a50eb30ea968", kubernetes version: "v1.18.2", go version: "go1.15 linux/amd64", GOOS: "linux", GOARCH: "amd64"

Possible Solution

As per the error message, Ansible doesn't look into the roles folder located at the root of the project. Only playbooks and playbooks/roles.
So I changed the Makefile from:

run: ansible-operator
	$(ANSIBLE_OPERATOR) run

to:

run: ansible-operator
	$(ANSIBLE_OPERATOR) run --ansible-roles-path "$(shell pwd)/roles"

And it worked.

So I suggest to change the default value in the template at https://github.com/operator-framework/operator-sdk/blob/master/internal/plugins/ansible/v1/scaffolds/internal/templates/makefile.go#L77.
What do you think?

Speaking of changes in the Makefile, I also added --zap-encoder console to the run command.
Otherwise I didn't find the JSON output very readable on a terminal.

When I think about it, what about forwarding arbitrary parameters like make run --any=parameter becoming ansible-operator ... --any=parameter?

Metadata

Metadata

Assignees

Labels

help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/bugCategorizes issue or PR as related to a bug.language/ansibleIssue is related to an Ansible operator project

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions