Ansible problem

Wszystko o rozwiązaniach Software-defined networking (SDN), OpenFlow, APIC-EM, ACI, REST API i pokrewnych
Wiadomość
Autor
martino76
CCIE
CCIE
Posty: 883
Rejestracja: 17 gru 2010, 15:23
Lokalizacja: Barczewo

Ansible problem

#1

#1 Post autor: martino76 »

Witam,

Zaczelem bawic sie ansible i mam maly problem, nie jestem w stanie wygenerowac template na podstawie zmiennych. Programowanie,to nie moja domena wiec prosze o wyrozumialosc, bo dopiero zaczynam zglebiac temat.

site.yml plik

Kod: Zaznacz cały

---
- name: template
  hosts: local
  roles:
    - routers
task file

Kod: Zaznacz cały

---
- name: template generator
  template: src={{ item.profile }}.j2 dest=/home/marcin/{{item.hostname}}.txt
  with_items: router
template file

Kod: Zaznacz cały

hostname {{item.hostname}}
interface loopback0
ip address {{ item.mgt_addr }}
{% for uplink in item.ports %}
interface {{ uplink.port_name }}
 description {{ uplink.name }}
 ip address {{ uplink.ip }} 255.255.255.252
 no shutdown
{% endfor %}  
var file

Kod: Zaznacz cały

---
router:  
  - hostname: R1
    profile: router
    mgt_addr: 1.1.1.1
    ports:
      - port_name: Eth0/0
        name: test
        ip: 10.10.10.1
        subnet: 255.255.255.0

kiedy odpalam ansible-playbook site.yml dostaje error jak ponizej.

Kod: Zaznacz cały

marcin@ubuntu:/etc/ansible$ ansible-playbook site.yml

PLAY [Generate router configuration files] *************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [routers : Generate configuration file] ***********************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode object' has no attribute 'hostname'\n\nThe error appears to have been in '/etc/ansible/roles/routers/tasks/main.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Generate configuration file\n  ^ here\n"}
 [WARNING]: Could not create retry file '/etc/ansible/site.retry'.         [Errno 13] Permission denied: u'/etc/ansible/site.retry'


PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1   

marcin@ubuntu:/etc/ansible$

Jakis pomysl gdzie robie blad?

Pozdro,

martino76
CCIE
CCIE
Posty: 883
Rejestracja: 17 gru 2010, 15:23
Lokalizacja: Barczewo

Re: Ansible problem

#2

#2 Post autor: martino76 »

Problem rozwiazany

w task file zmienilem

Kod: Zaznacz cały

  with_items: 
     "{{router}}"
Pozdro,

ODPOWIEDZ