I'm fairly new to ansible, so I'm still learning it.  Please bare with me.  
 I have a variable file that defines maps current hostnames of devices to 
new hostnames.  I'm trying to write a playbook that will re the variable 
file and change the hostnames of the devices.  So far I haven't had any 
luck, can some one tell me where I'm going wrong with this?  


The variable file and play book are pasted below

[joec@automation change_hostname]# cat hostname.yml
---
  - host: test13
    newhostname: test-switch1
  - host: jnpr-ans-test
    newhostname: test-switch2

[joec@automation change_hostname]# cat change_hostname.yml
---
- name: Examples of juniper_junos_command
  hosts: juniper
  gather_facts: no

  tasks:
    - include_vars:
        file: hostname.yml
        name: newnames
    - name: Get Facts.
      junos_facts:
        gather_subset: all
      register: facts

    - name: Rename device
      junos_facts:
        hostname: "{{ newnames.namehostname }}"
        when: facts.ansible_facts.ansible_net_hostname == newnames.host
        loop: "{{ newnames }}"

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6057f9e2-8dde-4328-a4e6-6087924e9659%40googlegroups.com.

Reply via email to