Ansible posix.mount模块ephemeral状态报错,升级后仍无法解决求助
解决Ansible临时挂载CIFS共享的报错问题
核心问题澄清
你混淆了两个Ansible集合的mount模块:ansible.posix.mount并不支持ephemeral状态,该状态是community.general.mount模块新增的特性,用于实现临时挂载且不修改fstab。
解决方向一:改用community.general.mount模块
- 先安装
community.general集合:
ansible-galaxy collection install community.general
- 修改你的任务代码:
- name: Mounting NAS2 share community.general.mount: path: /mnt/images src: //10.2.103.32/images fstype: cifs opts: "username=image,password={{ nas2_images }}" state: ephemeral
解决方向二:继续使用ansible.posix.mount实现临时挂载
ansible.posix.mount的state: mounted本身就可以实现临时挂载(不写入fstab),只要目标挂载点在fstab中没有对应的条目。任务代码调整为:
- name: Mounting NAS2 share temporarily ansible.posix.mount: path: /mnt/images src: //10.2.103.32/images fstype: cifs opts: "username=image,password={{ nas2_images }}" state: mounted
注:重启系统后该挂载会自动消失;若需手动卸载,执行
state: unmounted即可。
验证模块参数
你可以通过以下命令查看ansible.posix.mount的官方参数说明,确认state选项的有效值:
ansible-doc ansible.posix.mount
内容的提问来源于stack exchange,提问作者Jason Garner
相关产品推荐
相关产品推荐

