我写了我的第一个可靠的程序,并试图将文件输出到我的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]$
错误消息中明确指出了这个问题:
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"