ansible 将远程 nfs 共享挂载到本地主机服务器 运行 ansible playbook
ansible mount a remote nfs share to the localhost server running ansible playbook
当运行 ansible.posix.mount时,会创建到src的ssh连接,然后在所述服务器上创建路径目录。
我希望能够从远程服务器本地挂载 nfs 共享 运行 ansible 剧本。
我知道下面我的剧本中的第二个任务是在我清单中的“nfs-server”下的任何主机上执行上述任务,但是我需要包括该主机,因为它是我需要指向的目标 ip 变量挂载份额在。我不想将 IP 地址目标添加到我的 settings.yml,如果可能的话,我宁愿遍历清单文件。
我错过了什么?
这是我的剧本:
- name: Create directory
hosts: localhost
gather_facts: False
tasks:
- name: Include vars
include_vars:
file: settings.yaml
name: settings
- name: Create local directory "nfs-ansible"
file:
path: ./nfs-ansible
state: directory
delegate_to: localhost
- name: Mount nfs share to localhost
hosts: nfs-server
gather_facts: False
become: yes
tasks:
- name: Include idrac vars
include_vars:
file: settings.yaml
name: settings
- name: Mount share from nfs-server
ansible.posix.mount:
src: "{{ hostvars[inventory_hostname].ipaddress }}:/nfs-share"
path: ./nfs-ansible
state: mounted
fstype: nfs
从你的问题中我可以看出,你实际上并不想 运行 反对 nfs-server
组,你只是想使用它的 ipaddress
hostvar 要在本地挂载。如果理解正确:
- name: Create directory
hosts: localhost
gather_facts: False
tasks:
- name: Include vars
include_vars:
file: settings.yaml
name: settings
- name: Create local directory "nfs-ansible"
file:
path: ./nfs-ansible
state: directory
# delegate to is redundant in a playbook targeting "localhost" to begin with
# delegate_to: localhost
- name: Mount share from nfs-server
become: yes
ansible.posix.mount:
src: "{{ hostvars[nfs_server0].ipaddress }}:/nfs-share"
path: ./nfs-ansible
state: mounted
fstype: nfs
vars:
nfs_server0: '{{ groups["nfs-server"] | first }}'
当运行 ansible.posix.mount时,会创建到src的ssh连接,然后在所述服务器上创建路径目录。 我希望能够从远程服务器本地挂载 nfs 共享 运行 ansible 剧本。
我知道下面我的剧本中的第二个任务是在我清单中的“nfs-server”下的任何主机上执行上述任务,但是我需要包括该主机,因为它是我需要指向的目标 ip 变量挂载份额在。我不想将 IP 地址目标添加到我的 settings.yml,如果可能的话,我宁愿遍历清单文件。
我错过了什么?
这是我的剧本:
- name: Create directory
hosts: localhost
gather_facts: False
tasks:
- name: Include vars
include_vars:
file: settings.yaml
name: settings
- name: Create local directory "nfs-ansible"
file:
path: ./nfs-ansible
state: directory
delegate_to: localhost
- name: Mount nfs share to localhost
hosts: nfs-server
gather_facts: False
become: yes
tasks:
- name: Include idrac vars
include_vars:
file: settings.yaml
name: settings
- name: Mount share from nfs-server
ansible.posix.mount:
src: "{{ hostvars[inventory_hostname].ipaddress }}:/nfs-share"
path: ./nfs-ansible
state: mounted
fstype: nfs
从你的问题中我可以看出,你实际上并不想 运行 反对 nfs-server
组,你只是想使用它的 ipaddress
hostvar 要在本地挂载。如果理解正确:
- name: Create directory
hosts: localhost
gather_facts: False
tasks:
- name: Include vars
include_vars:
file: settings.yaml
name: settings
- name: Create local directory "nfs-ansible"
file:
path: ./nfs-ansible
state: directory
# delegate to is redundant in a playbook targeting "localhost" to begin with
# delegate_to: localhost
- name: Mount share from nfs-server
become: yes
ansible.posix.mount:
src: "{{ hostvars[nfs_server0].ipaddress }}:/nfs-share"
path: ./nfs-ansible
state: mounted
fstype: nfs
vars:
nfs_server0: '{{ groups["nfs-server"] | first }}'