On 13. juni 2016 19:50, Jerome Yanga wrote:
vars/main.yml
host_entries:

Here you have host_entries


  - { srv_loc:  'ca', ip_addr:  '10.1.1.1', host_aliases:
  'ca-srv-01.example.com ca-srv-01' }
  - { srv_loc:  'ny', ip_addr:  '10.2.1.1', host_aliases:
  'ny-srv-01.example.com ny-srv-01' }
  - { srv_loc:  'co', ip_addr:  '10.3.1.1', host_aliases:
  'co-srv-01.example.com co-srv-01' }

tasks/main.yml
---

  - name: checking location of server
    raw:  'echo "{{ ansible_hostname }}" | cut -f1 -d"-"'
    register: actual_loc

  - name: adding entries in the hosts file
    lineinfile:
       backup:  yes
       create:  yes
       dest:  /etc/hosts
       group:  root
       line:  "{{item.ip_addr}}     {{item.host_aliases}}"
       mode:  0644
       owner:  root
       state:  present
    when:  ( actual_loc.stdout_lines == item.srv_loc )
    with_items:  "{{ hosts_entries }}"

But here you have hosts_entries, so one of them is a typo.

You could lose the raw by doing so in the when
when: ansible_hostname.split('-')[0] == item.srv_loc

--
Kai Stian Olstad

--
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/57602677.5060406%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to