Ansible Playbook执行失败排查请求:remote_user配置失效、unarchive模块报错及文件权限异常
Let's break down and fix the three key issues you're facing with your Ansible Playbook:
1. Fix the Unarchive Module Failure
The error message clearly points to the root cause:
Could not find or access '/home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz' on the Ansible Controller
By default, the unarchive module looks for files on your local Ansible controller and uploads them to remote nodes. But your tar.gz file is already downloaded directly to the remote server via get_url. To fix this, add the remote_src: yes parameter to tell the module to use the file on the remote node:
- name: unzip tar file unarchive: src: /home/ldb/servicebroker/servicebroker-4.1.0-rc6.x86_64.tar.gz dest: /home/ldb/servicebroker/ remote_src: yes # Critical parameter to resolve the file not found error
2. Correct File Ownership (Root Instead of ldb)
Your downloaded files are owned by root because either:
- The Playbook is running with elevated privileges (
become: yes) without explicitly setting ownership, or - The
remote_user: ldbsetting isn't taking effect, so tasks run as root by default.
Fix Steps:
- Ensure the download directory belongs to ldb:
- name: Create download directory file: path: /home/ldb/servicebroker state: directory owner: ldb group: ldb mode: 0755 - Force file ownership in the
get_urltask:- 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 owner: ldb # Set owner explicitly group: ldb # Set group explicitly 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
3. Make remote_user: ldb Take Effect
If the remote_user setting isn't working, check these common causes:
- Inventory Override: Verify your inventory file (e.g.,
hosts) isn't overriding the user for thedbgroup. Look for lines like:
Change[db] 192.168.14.94 ansible_user=rootansible_usertoldbor remove this line to respect the Playbook'sremote_usersetting. - Ansible.cfg Global Setting: Check your
ansible.cfgfile for a globalremote_userparameter that's set toroot:
Either modify this to[defaults] remote_user = rootldbor explicitly setansible_user: ldbin your Playbook (it takes priority overremote_user). - Become Configuration: If you have
become: yesenabled (either in the Playbook oransible.cfg) withbecome_user: root, tasks will run as root regardless ofremote_user. If you don't need elevated privileges, removebecome: yes. If you do need it, keep using theowner/groupparameters in tasks to enforce file ownership.
Bonus: Fix a Typo in the Slave Start Task
Your Start slave task has a duplicate brokerServer in the shell command. Correct it to:
- name: Start slave shell: "/home/ldb/servicebroker/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
内容的提问来源于stack exchange,提问作者YanGang

