DEV Community

Roy
Roy

Posted on

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

Latest comments (0)