0

I've got a hosts file for multiplexing in Ansible

[masters]
master ansible_host=10.10.1.1 ansible_ssh_user=root ansible_ssh_pass=froyo 

[workers]
worker1 ansible_host=10.10.1.2 ansible_ssh_user=root ansible_ssh_pass=froyo
worker2 ansible_host=10.10.1.3 ansible_ssh_user=root ansible_ssh_pass=froyo

and I'm wanting to make a shell command to set node names

- hosts: workers
  become: yes
  tasks:
    - name: join cluster
      shell: "{{ hostvars['master'].join_command }} --node-name {{self.name}} >> node_joined.txt"
      args:
        chdir: $HOME
        creates: node_joined.txt

The Q/A in How to get the host name of the current machine as defined in the Ansible hosts file? identified to include inventory_hostname, however this did not work for me .. I could change the hostnames of the workers, which is what I want to avoid.

from the above play i'm expecting two nodes to be identified in master via the names worker1 and worker2 that exist in the hosts file.

i couldn't set anything: inventory_hostname or others including ansible_hostname and ansible_nodename. is there any way to access the names worker1 and worker2 from the hosts? it doesn't seem the variables from ansible -i hosts worker1 -m setup can be set... please help me identify what i'm missing, thanks in advance

aug2uag
  • 3,379
  • 3
  • 32
  • 53

1 Answers1

-2

You need to limit the playbook to worker1

Try:

ansible-playbook -i hosts --limit worker1 -m setup

amb1s1
  • 1,995
  • 5
  • 22
  • 26