'Ansible Playbook: remote_user is ncorrect ,switching failed
I write playbook for download and install and unarchive tar file:
- 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
But run failed and get error info:
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"}
I found db file owner is root user, not ldb user:
-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 Apr 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 not enable.Please help check! Thanks!
Solution 1:[1]
I think you just need to look at the error more closely:
"Could not find or access '/home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz' *on the Ansible Controller*.
You are downloading the file remotely, but trying to access it locally on the controller. In unarchive where you say:
src: /home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz
Try:
src: /home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz
remote_src: yes
Note the documentation for unarchive here:
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/unarchive_module.html
Also note: the error is saying the ldb user doesn't have a shell assigned. Ansible can't login as it. Assuming it is the service account to run a service, you probably don't want to make it an interactive user just for Ansible's sake.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matt Blaha |
