Ansible Playbook:remote_user 不正确,切换失败

Ansible Playbook: remote_user is ncorrect ,switching failed

我编写了用于下载、安装和解压缩的剧本 tar 文件:

 - name: Install DB
     remote_user: ldb
     hosts: db
     tasks:
       - name: Create download directory
         file:
            path: /home/ldb/servicebroker
            state: directory

       - name: download DB and service_broker
         get_url:
             url:  "http://192.168.1.133:12345/stage/{{ item }}"
             dest: /home/ldb/servicebroker
             mode: 0755
             timeout: 30
         with_items:
              - linkoopdb/4.1.0/zettabase-4.1.0-rc6.x86_64.iso
              - service_broker/4.1.0/servicebroker-4.1.0-rc6.x86_64.tar.gz

       - name: unzip tar file
         unarchive:
           src:  /home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz
           dest: /home/ldb/servicebroker/

       - name: Start master
         shell: "/home/ldb/servicebroker/brokerServer --master_ip 192.168.14.94  --master_port 7777"

       - name: Start slave
         shell: "/home/ldb/servicebroker/brokerServer brokerServer --master_ip 192.168.14.94 --master_port 7777  --slave_ip {{ item }} --slave_port 7777 join"
         with_items:
            - 192.168.14.95
            - 192.168.14.94
            - 192.168.14.96
            - 192.168.14.97
            - 192.168.14.37
            - 192.168.14.38
            - 192.168.14.39

       - name: Check for servicebroker command
         shell:  /home/ldb/servicebroker/bcli show service_broker,
         register: command_output

       - name: Start create repository and upload  install DB
         shell: "{{ item }}"
         retries: 3
         delay: 10
         register: command_output
         with_items:
           -  /home/ldb/servicebroker/bcli create repository db1
           -  /home/ldb/servicebroker/bcli show repository all
           -  /home/ldb/servicebroker/bcli upload zettabase-4.1.0-rc6.x86_64.iso

       - name: Print result
         debug: 
             var: command_output.stdout_lines

但是 运行 失败并得到错误信息:

fatal: [192.168.14.96]: FAILED! => {"changed": false, "msg": "Could not find or access '/home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}

我发现 db 文件的所有者是 root 用户,而不是 ldb 用户:

-rwxr-xr-x 1 root root 2162550784 Apr 19 19:36 base-4.1.0-rc6.x86_64.iso -rwxr-xr-x 1 root root 3918489072 4 月 19 日 19:47 base-4.1.0-rc6.x86_64.tar.gz -rwxr-xr-x 1 root root 31523406 Apr 19 20:03 servicebroker-4.1.0-rc6.x86_64.tar.gz

remote_user:ldb不行enable.Please帮忙查一下!谢谢!

我认为你只需要更仔细地查看错误:

"Could not find or access '/home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz' *on the Ansible Controller*.

您正在远程下载文件,但试图在控制器上本地访问它。在您说的取消存档中:

src:  /home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz

尝试:

src:  /home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz
remote_src: yes

请注意此处的解档文档:

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/unarchive_module.html

另请注意:错误是说 ldb 用户没有分配 shell。 Ansible 无法登录。假设它是 运行 一项服务的服务帐户,您可能不想仅仅为了 Ansible 的缘故而将其设为交互式用户。