Select another interface for remote execution massively

Problem:
I have like 900 hosts already registered, and I’m updating them through remote execution. I encountered that a lot of them do not have the right network interface selected for remote execution (a considerable number of hosts have more than 2 network interfaces registered).

Expected outcome:
I would like to know If there’s a way to change the network interface for remote execution through CLI or something to work around other than doing it through foreman > all hosts > desired_host > interfaces

Foreman and Proxy versions:
F 3.2
K 4.4

Foreman and Proxy plugin versions:

Distribution and version:
Oracle Linux Server 8.5

Other relevant data:
I was thinking with some hammer CLI, but I would like to know If there’s another way.

It should be doable using hammer on 3.3, but I’m afraid the changes didn’t get into 3.2.

There are some quirks which make this cumbersome in pre-3.3 and which were removed in 3.3. Remote execution has some checks that enforce that a host:

  1. does not have more than 1 execution interface
  2. If the host does not have an execution interface, the primary interface becomes the execution interface

For example let’s take this host

# hammer host interface list --host flowing-escargot.example.com 
---|------------|-------------------------------------------|-------------------|-----------------|-----------------------------
ID | IDENTIFIER | TYPE                                      | MAC ADDRESS       | IP ADDRESS      | DNS NAME                    
---|------------|-------------------------------------------|-------------------|-----------------|-----------------------------
2  | eth0       | interface (primary, provision, execution) | 00:16:3e:10:8e:84 | 192.168.125.181 | flowing-escargot.example.com
3  | lo         | interface                                 |                   | 127.0.0.1       | localhost                   
---|------------|-------------------------------------------|-------------------|-----------------|-----------------------------

If I try to set lo to be the execution interface, it fails because eth0 is already an execution interface (see 1). If I try to unset eth0 as execution interface, it will immediately get re-marked as execution because it is also a primary interface.

As a workaround (this should work even in possibly any version), we can perform both changes at once with curl

# cat <<EOF >/tmp/json
{"host": {
  "interfaces_attributes": [
    {"id": 2, "execution": false},
    {"id": 3, "execution": true}
  ]
}}
EOF

# curl -X PUT https://$FOREMAN_FQDN/api/hosts/$HOST_ID -H 'Content-Type: application/json' -u $USER:$PASS -d @/tmp/json
-----B<-----SNIP-----B<-----

# hammer host interface list --host flowing-escargot.example.com 
---|------------|--------------------------------|-------------------|-----------------|-----------------------------
ID | IDENTIFIER | TYPE                           | MAC ADDRESS       | IP ADDRESS      | DNS NAME                    
---|------------|--------------------------------|-------------------|-----------------|-----------------------------
2  | eth0       | interface (primary, provision) | 00:16:3e:10:8e:84 | 192.168.125.181 | flowing-escargot.example.com
3  | lo         | interface (execution)          |                   | 127.0.0.1       | localhost      
3 Likes

Thank you! I’m gonna check on this workaround!