Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

348
Views
ansible ansible_default_ipv4 estableció una interfaz incorrecta

Estoy tratando de configurar un host y seleccionar automáticamente la interfaz relevante.
Para eso estoy tratando de ejecutar la tarea de Ansible:

 - name: Set the list of interfaces to be configured network_interfaces_to_configure: "{{ ansible_interfaces | difference([ ansible_default_ipv4.alias, 'lo', 'docker0' ]) }}"

Por alguna razón, almacena en network_interfaces_to_configure una interfaz que está desactivada: la configura en enp1s0f1 y debería configurarse en enp1s0f0

El host tiene las siguientes interfaces:

  • hola
  • docker0 (virtual)
  • enp1s0f0 (hardware conectado y habilitado)
  • enp1s0f1 (hardware deshabilitado y sin ninguna conexión física)

También verifiqué que la puerta de enlace predeterminada está configurada en enp1s0f0 .

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

La razón por la que termina con la interfaz incorrecta es porque está excluyendo la correcta en su filtro de difference .

 difference([ ansible_default_ipv4.alias, 'lo', 'docker0' ]) ## ^--- it is excluded because of this addition ## of `ansible_default_ipv4.alias` in the list

Ahora, como indicó que enp1s0f1 debe excluirse porque es una interfaz inactiva, tendrá que profundizar más en las propiedades de esas interfaces.

Para hacer esto, debe saber que la lista dentro de ansible_interfaces corresponde a ansible_* hechos que enumeran más información para esas interfaces.

Por ejemplo, en tu caso, tendrás esos hechos:

  • ansible_lo
  • ansible_docker0
  • ansible_enp1s0f0
  • ansible_enp1s0f1

Con información como:

 ansible_lo: active: true device: lo ipv4: address: 127.0.0.1 broadcast: '' netmask: 255.0.0.0 network: 127.0.0.0 mtu: 65536 promisc: false type: loopback

Entonces, tal vez, una mejor idea sería crear un hecho y excluir interfaces en función de sus propiedades active y de type .

Algo como:

 - set_fact: active_interfaces: "{{ active_interfaces | default([]) + [item] }}" loop: "{{ ansible_interfaces }}" when: ## only include active interfaces - lookup('vars', 'ansible_' ~ item).active ## exclude local loopback interfaces (`lo`) - lookup('vars', 'ansible_' ~ item).type != 'loopback' ## exclude bridge interfaces (`dockerO`) - lookup('vars', 'ansible_' ~ item).type != 'bridge'

Luego, use esa variable en network_interfaces_to_configure :

 - network_interfaces_to_configure: "{{ active_interfaces }}"

Este sería un ejemplo de lo que esto da en mi propia configuración, dado el libro de jugadas:

 - hosts: localhost gather_facts: yes tasks: - set_fact: active_interfaces: "{{ active_interfaces | default([]) + [item] }}" loop: "{{ ansible_interfaces }}" when: - lookup('vars', 'ansible_' ~ item).active - lookup('vars', 'ansible_' ~ item).type != 'loopback' - lookup('vars', 'ansible_' ~ item).type != 'bridge' - debug: var: active_interfaces

Esto produce:

 TASK [Gathering Facts] ********************************************************* ok: [localhost] TASK [set_fact] **************************************************************** ok: [localhost] => (item=eth0) skipping: [localhost] => (item=tunl0) skipping: [localhost] => (item=docker0) skipping: [localhost] => (item=lo) ok: [localhost] => (item=services1) skipping: [localhost] => (item=ip6tnl0) TASK [debug] ******************************************************************* ok: [localhost] => active_interfaces: - eth0 - services1
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!