재고 파일 ^

재고 파일 ^

다음은 Cisco 장치의 ansible 구성을 위한 yaml 파일입니다. /etc/ansible/hosts에서 아래에서 볼 수 있듯이 Amazon EC2 Ami 인스턴스를 반영하도록 호스트 파일도 편집했습니다.

[ec2-instances]
ec2-54-152-72-23.compute-1.amazonaws.com

재고 파일 ^

아래 YAML 파일

---
-  hosts: ec2-54-152-72-23.compute-1.amazonaws.com
   gather_facts: false
   connection: local

   tasks:
    -name:  Customer IOS Upgrade Initial Discovery
    cli_command: "{{ show }}"

    vars: 
      show:
       - show run
       - show version
       - show interface status
       - show license


    -mail: 
      host: smtp.gmail.com
      port: 587
      username: [email protected]
      password: sample2
      to: [email protected]
      subject: '{{ ansible_hostname }} configuration' 
      body: 'System {{ ansible_hostname }} has been successfully discovered.'
      delegate_to: localhost

    save_when: changed   
...

다음을 실행하려고 하면 다음 오류 메시지가 나타납니다. 왜 이런 일이 발생하는지 아시나요? [ec2-instances]와 함께 제공되는 초기 .yaml 파일에 표시된 내용을 전환했지만 여전히 런타임 결과에는 차이가 없습니다.

ansible-playbook -i /etc/ansible/hosts test2.yml --user ec2-user --private-key=/home/adam/Desktop/EC2CSR1000v.pem -vvv
ansible-playbook 2.7.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/adam/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
Parsed /etc/ansible/hosts inventory source with ini plugin
ERROR! A malformed block was encountered while loading tasks

The error appears to have been in '/etc/ansible/scripts/test2.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
-  hosts: [ec2-instance]
   ^ here

답변1

먼저 순수함을 고쳐야합니다YAML.

전역적으로 작업과 관련된 옵션이나 특정 모듈의 매개변수인 옵션에 주의를 기울여야 합니다. 해당 옵션은 올바른 범위를 반영하도록 올바르게 들여쓰기되어야 합니다.

사용하려는 모듈에 대한 문서를 반드시 읽어야 합니다. 예를 들어,cli_command문자열을 직접 허용하지만 명시적인 command옵션과 기타 옵션이 필요합니다. 목록을 허용하지 않으므로 다른 명령을 반복해야 합니다.

마지막으로 확인해야 할 몇 가지 이상한 점이 있습니다.

  • 플레이의 대상으로 단일 원격 호스트를 제공하지만(괜찮습니다) 로컬 연결을 나열합니다. 이것이 실제로 원격 호스트인 경우 SSH로 연결해야 하므로 작동할 수 없습니다.
  • 당신은 작업 옵션을 사용하고 있습니다 save_when. 나는 그것이 오류로 인해 파일 끝에 있다는 것을 알고 있으며 cli_command모듈 호출과 함께 사용해야 한다고 생각합니다. 한편 이는 이 모듈의 매개변수로 나열되지 않습니다(그러나 다른 관련 매개변수의 일부입니다).시스코 iOS 모듈

이 시점에서 나는 당신이 정확히 무엇을 원하는지 알 수 없으므로 내가 옳다고 생각하는 플레이북만 수정하여 당신이 앞으로 나아갈 수 있도록 할 수 있습니다.

---
- name: Playbook to manage my cisco IOS devices
  hosts: ec2-54-152-72-23.compute-1.amazonaws.com
  gather_facts: false

  tasks:
    - name: Customer IOS Upgrade Initial Discovery
      cli_command:
        command: "{{ item }}"
      loop:
        - show run
        - show version
        - show interface status
        - show license

    - name: Send a feedback by email
      mail:
        host: smtp.gmail.com
        port: 587
        username: [email protected]
        password: sample2
        to: [email protected]
        subject: '{{ ansible_hostname }} configuration' 
        body: 'System {{ ansible_hostname }} has been successfully discovered.'
      delegate_to: localhost

관련 정보