DEV Community

Roy
Roy

Posted on

2 2

the value of ansible_hostname is not fixed after the fact gathering

- name: common configuration
  hosts: poc-3

  tasks:
    - name: set hostname
      ansible.builtin.hostname:
        name: "bk-{{ ansible_default_ipv4.address.split('.')[-1] }}"
      notify:
        - hostname changed

    - debug:
        var: ansible_hostname

  handlers:
    - name: update /etc/hosts
      ansible.builtin.replace:
        path: /etc/hosts
        regexp: "{{ ansible_hostname }}"
        replace: "bk-{{ ansible_default_ipv4.address | split('.') | last }}"
      listen: "hostname changed"
Enter fullscreen mode Exit fullscreen mode

alt text

the value of ansible_hostname changed after I update the hostname of system, it is not fixed after fact gathering

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay