第一个 Ansible 程序 - 将输出存储到文件时出错

第一个 Ansible 程序 - 将输出存储到文件时出错

我编写了我的第一个 ansible 程序,并尝试将文件输出到我的 Linux 机器上的新位置。可能是语法错误。我希望将文件的输出(显示版本)转储到新文件中。这是我使用的代码。这是复制/内容部分的正确语法吗?:

vi test2-playbook.yml

---
- hosts: localhost
  gather_facts: false
  connection: local

  tasks:
   - name: run show version on ios device
     ios_command:
       commands:
         - show version
       host: rf3.cor.las.ss34.net
       username: cisco
       password: cisco

     register: show_output

   - name: show output
     debug:
        var: show_output

   - name: display to a file in new folder
     copy: content = "{{show_output}}" dst= "/home/hellow/test1/rf3.cor.las.txt"

=====================

运行该文件但在显示任务上出现以下错误:

}

TASK [display to a file] *******************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "src (or content) and dest are required"}
        to retry, use: --limit @/home/tmalhotra/Ansible_learning/test2-playbook.retry

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

[tmalhotra@lasssnpr01net01 Ansible_learning]$ 

答案1

错误信息中明确说明了这个问题:

src (or content) and dest are required

您的任务包含一个content参数,但目标参数不正确(dst而不是dest

另外,尝试在最后一个任务中使用正确的 YAML:

$ ansible-playbook some.yml

PLAY [localhost]  ***************************************************************

TASK [display to a file in new folder] *****************************************
changed: [127.0.0.1]

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

$ cat some.yml
---
- hosts: localhost
  gather_facts: false
  connection: local
  tasks:
    - name: display to a file in new folder
      copy:
        content: "foo"
        dest: "/home/david/test.txt"

相关内容