2 years ago

#51113

test-img

İlker Demirci

Trying to get Hostname from A group

I am trying to get the inventory_hostname from a hosts group I created.

What I am really trying to achieve is copying a file with a new name to a remote server, while its new name will be other remote servers hostname.

{{ inventory_hostname }} gives IP address and {{ ansible_hostname }} returns hostname as default variables but while doing this, I am stuck:

- name: Copy File
  hosts: nagios
  become: yes

  tasks:
    - shell: cp /home/xxx/test.txt /home/xxx/{{ item }}.txt
      with_items: "{{ groups['dbs'] }}"

{{ item }} returns the IP address but I want the hostname, not the IP for this one. Any help would be appreciated.

ansible

hostname

0 Answers

Your Answer

Accepted video resources