使用Ansible在远程机器上安装点附件

时间:2019-07-02 12:38:44

标签: server ansible

  • 我正在尝试使用ansible将挂载点添加到远程计算机。
  • 必须附加的安装点是另一个服务器的文件夹。
  • 我写了下面的ansible脚本来做到这一点,但是挂起了,没有任何反应。

- hosts: all
  remote_user: deepcompute
  become: true
  become_method: sudo
  tasks:
  - name: Adding SSH key
    authorized_key:
        user: deepcompute
        state: present
        manage_dir: yes
        key: "{{lookup('file','/home/deepcompute/personal/test_class/data.pub')}}"

  - name: Adding mount point in fstab
    lineinfile:
        path: /etc/fstab
        line: "user@machine1.servers.nferx.com:/home/deepcompute/hpcentraldata/ /example_mount/ fuse.sshfs _netdev,user,idmap=user,transform_symlinks,identityfile=/home/deepcompute/.ssh/id_rsa,allow_other,default_permissions,reconnect,ServerAliveInterval=20,ServerAliveCountMax=5,uid=1000,gid=1000 0 0"

  - name: Mount Directory Example
    file:
      path: /example_mount
      state: directory
    notify:
        - Change Permission

  handlers:
  - name: Change Permission
    file:
        path: /example_mount
        owner: user
        group: user
        state: directory
    notify:
        - Add mount point

  - name: Add mount point
    mount:
        path: /example_mount
        src: user@machine2.servers.nferx.com:/home/deepcompute/hpcentraldata
        fstype: ext4
        state: mounted
        opts: bind

因此在上面的脚本中,我将在新服务器中创建一个安装点。

1 个答案:

答案 0 :(得分:0)

使用mount模块。

- mount:
    src: 'user@machine1.servers.nferx.com:/home/deepcompute/hpcentraldata/'
    name: '/example_mount/'
    fstype: 'fuse.sshfs'
    opts: '_netdev,user,idmap=user,transform_symlinks,identityfile=/home/deepcompute/.ssh/id_rsa,allow_other,default_permissions,reconnect,ServerAliveInterval=20,ServerAliveCountMax=5,uid=1000,gid=1000'