我有一个 Ansible 任务:
- name: Ensure Gluster volume is mounted.
mount:
name: "{{ mount_dir }}"
src: "{{ inventory_hostname }}:{{ brick_name }}"
fstype: glusterfs
opts: "defaults,_netdev"
state: mounted
失败并输出:
fatal: [remotehost.com]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"dump": null, "fstab": "/etc/fstab", "fstype": "glusterfs", "name": "ssl", "opts": "defaults,_netdev", "passno": null, "src": "remotehost.com:/craik/clm/ssl", "state": "mounted"}, "module_name": "mount"}, "msg": "Error mounting ssl: Mount failed. Please check the log file for more details.\n"}
是否可以看到 Ansible 将挂载任务转换为的实际 Unix 命令?
例如:
mount -t glusterfs remotehost.com:/craik/clm/ssl /srv/gluster/ssl
最佳答案
Ansible 使用 Python 脚本来执行其操作(它可能会从 Python 调用外部程序,但如果没有必要,则不会)。
您可以在执行 ansible-playbook
之前将 ANSIBLE_KEEP_REMOTE_FILES=1
添加到控制计算机上的环境中,从而使 Ansible 保留在目标计算机上运行的实际脚本.
例如,如果您运行:
ANSIBLE_KEEP_REMOTE_FILES=1 ansible-playbook playbook.yml -vvv
您将在文字记录中看到类似以下内容:
PUT /var/folders/nw/2vnhg_gj77v_cyfv0p1vdfj80000gn/T/tmpidULyi TO /home/vagrant/.ansible/tmp/ansible-tmp-1484137690.32-255077767492235/mount.py
然后,如果您打开 mount.py
,您可以验证实际代码(您也可以重新运行它)。
关于unix - 如何查看Ansible运行的Unix命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41590017/