老师 ,请教下这个问题
来源:6-17 playbook剧本中的变量定义方式
sunshinebao
2018-05-12
more f4.yml
---
- hosts : 192.168.226.129
remote_user : root
vars :
touch_file : imoocc.file
tasks :
- name : get date
command : date
register : date_output
- name : touch file
shell : "touch /tmp/{{touch_file}}"
- name : echo date_output
shell : "echo {{date_output.stdout}}>/tmp/{{touch_file}}"
root@ubuntu:/etc/ansible# ansible-playbook ./f4.yml
PLAY [192.168.226.129] ******************************************************************
TASK [Gathering Facts] ******************************************************************
ok: [192.168.226.129]
TASK [get date] *************************************************************************
changed: [192.168.226.129]
TASK [touch file] ***********************************************************************
[WARNING]: Consider using file module with state=touch rather than running touch
changed: [192.168.226.129]
TASK [echo date_output] *****************************************************************
fatal: [192.168.226.129]: FAILED! => {"changed": true, "cmd": "echo Fri May 11 15:52:00 PDT 2018>/tmp/imoocc.file", "delta": "0:00:00.002548", "end": "2018-05-11 15:52:01.370891", "failed": true, "msg": "non-zero return code", "rc": 1, "start": "2018-05-11 15:52:01.368343", "stderr": "/bin/sh: 2018: Bad file descriptor", "stderr_lines": ["/bin/sh: 2018: Bad file descriptor"], "stdout": "", "stdout_lines": []}
to retry, use: --limit @/etc/ansible/f4.retry
PLAY RECAP ******************************************************************************
192.168.226.129 : ok=3 changed=2 unreachable=0 failed=1
2回答
-
tasks :
- name : get date
command : date
register : date_output将这个地方配置修改下,修改为,如下:
tasks :
- name : get date
command :date +%Fregister : date_output
再执行测试下,看看是否能正常?
012018-05-12 -
sunshinebao
提问者
2018-05-12
现在可以运行成功了,我现在是搞运维的,希望今年多学一些运维开发的知识,多谢老师的耐心指导。
00
相似问题