Delegation issues

,

Hello Folks,

We were using AWX 15.x for quite a time & used “delegate_to: 127.0.0.1 or localhost” quite effectively to run tasks on controller node.

Recently on upgrade to AWX 23.x, we found issues with delegation.

delegate_to: 127.0.0.1
Above is now running on the execution environment pod if i understand right. This fails as we have firewall policies tied to controller host & the pod cannot connect to other hosts. This delegation is needed for just a handful of steps & all others work good.

Was able to get around by coding the name of AWX master but this doesn’t look flexible as playbooks are not tied to this instance & we loose portability.
delegate_to: “AWX master”

Kindly share thoughts what’s the best strategy to delegate to AWX master.

Hi,
As you mentionned, i think the best is to have a firewall rule that allow traffic from pods subnet to the target subnet/hosts you need to work on.

That’s how I manage it in my situation.

Ouch, we tried that approach for another use case but network team struck it down that source sub-nets won’t be allowed. It has to be precise ip.

Just wondering, how do i figure out what subnet will AWX use to spawn pods?

I’m not a Kubernetes expert at all but workers takes IP from DHCP. So except Ingress that is static, you can’t have a precise ip unfortunately. Moreover, everytime you launch a job it creates a temporary pod which takes IP from a DHCP subnet.

Imho you have to specify a subnet to make it works.

Here’s an analogy but it’s like having a car, you have to press brake pedal to brake, but network team tell you to use something else cause they don’t know what braking is…

Unless I’m misunderstanding something here, the pods inside a kubernetes cluster get launched with an internal IP from an internal IP CIDR yes (defaulting to the 172 subnet (certain distributions may vary, but you get the point)). However, when the pods go and reach for things outside of the kubernetes cluster, such as Ansible targets, the real network your Network guys probably care about will see traffic originating from the kubernetes host’s IP. Your network team needs to allow the kubernetes hosts’s IP addresses, not the kubernetes clusters’s internal cluster IP addresses for pods.

I have no idea why your delegation to localhost would be failing, to the OP’s question. However, I can’t imagine your Network team would somehow be able to insert a firewall from inside the kubernetes cluster itself. I think it’d also need to block the pod from talking to itself, too. That’d be quite a feat.

1 Like

@mcen when you say “Your network team needs to allow the kubernetes hosts’s IP addresses, not the kubernetes clusters’s internal cluster IP addresses for pods.”

Are we agree that hosts IP address are most of time delivered by DHCP ? (i mean every time we provide a k8s cluster we have to tell cidr subnet used for nodes)

1 Like

Ohhh, I see. The kubernetes hosts are getting DHCP assignments. That was the missing piece for me. My apologies. Though I dunno if the OP’s org is provisioned that way.

If they are, seems odd for a Network team to permit DHCP assignments but then disallow CIDRs for rules, but Network people can be odd.

1 Like

That’s more or less what i said 3 comments earlier :grin:

1 Like

If you delegate to localhost literally, Ansible uses the local connection plugin defined by default for this host, no network connection of any kind. If you use localhost instead of 127… does it work?

Thanks for the inputs folks.

Few more clarification on environment.
This is AWX 23.9.0 hosted on standalone cluster created via k3s.

However, when the pods go and reach for things outside of the kubernetes cluster, such as Ansible targets, the real network your Network guys probably care about will see traffic originating from the kubernetes host’s IP

Doubt, apparently it’s taking pod’s IP.

Your network team needs to allow the kubernetes hosts’s IP addresses

Kubernetes host’s IP is already allowed. That’s why when i delegate to AWX master server it passed but fails with localhost or 127.0.0.1

If you use localhost instead of 127… does it work?

Nope, both localhost & 127.0.0.1 are failing.
Only coding AWX server is getting good results.

@vibhor_agarwalin so it means your network teams have allowed subnet configured in your pods, are we agree ?
You can double check with :

kubectl get nodes -o wide

The internal IP column is the subnet you have to allow.

Also, i’ve just had a look to some projects of mine that use localhost in a play part and it’s ok.

No, subnet hasn’t been allowed.
Only AWX master server is allowed.

Our playbooks had localhost which wasn’t working, hence, had to code it to AWX server hostname to get it working.

Ok but if your playbook use localhost and it isn’t working, i think there still a network issue due to your firewall.

What do you mean by “had to code it to AWX server hostname” ?

In my side, “localhost” can be used by any playbook on any projects.
It doesn’t belong to any groups, doesn’t have any facts.

The result is, it’s just a host like another one. When I use it, it means tasks are executed by the AWX pod itself and not pods that are created only during the time of execution.

Let’s say AWX server is installed on host “Abc”.

Playbooks with the following were failing:

delegate_to: localhost
delegate_to: 127.0.0.1

However, this is passing:

delegate_to: Abc

When I use it, it means tasks are executed by the AWX pod itself and not pods that are created only during the time of execution.

By AWX pod here do we mean the task or web pod?
Either way it may be same as these will have different ip addresses than AWX server.

I’m confused. What’s the output for the error in the playbook/template/task when it fails delegate_to: localhost? I can’t imagine what the error is with the local connection plugin. Can you try to run it with maximum verbosity (3 - debug)?

Error is can’t connect to host (precise words i don’t have handy).
In effect delegation doesn’t fail, connecting to remote server from localhost fails which is allowed only from AWX master server.

In that case why don’t you create a host with variables ansible_connection: local within AWX/AAP and then use Abc instead of localhost ? (as mentionned i’m doing the same but I create a host called localhost in AWX)

EDIT: here’s an explanation support "delegate_to: localhost" · Issue #1006 · ansible/awx · GitHub

Seems i already have that in AWX

Is this good or am i missing something?

It seems good.
Could you share the error you have (=awx job output) when using localhost please ?