0

来自Ansible:我可以从命令行执行角色吗?-

HOST_PATTERN=$1
shift
ROLE=$1
shift

echo "To apply role \"$ROLE\" to host/group \"$HOST_PATTERN\"..."

export ANSIBLE_ROLES_PATH="$(pwd)/roles"
export ANSIBLE_RETRY_FILES_ENABLED="False"

ANSIBLE_ROLES_PATH="$(pwd)/roles" ansible-playbook "$@" /dev/stdin <<END
---
- hosts: $HOST_PATTERN
  roles:
    - $ROLE
END

问题是当我运行时./apply.sh all dev-role -i dev-inventory,它无法承担正确的角色。当我运行时ansible-playbook -i dev-inventory site.yml --tags dev-role,它正在工作。

下面是错误信息

fatal: [my-api]: FAILED! => {"changed": false, "checksum_dest": null, "checksum_src": "d3a0ae8f3b45a0a7906d1be7027302a8b5ee07a0", "dest": "/tmp/install-amazon2-td-agent4.sh", "elapsed": 0, "gid": 0, "group": "root", "mode": "0644", "msg": "Destination /tmp/install-amazon2-td-agent4.sh is not writable", "owner": "root", "size": 838, "src": "/home/ec2-user/.ansible/tmp/ansible-tmp-1600788856.749975-487-237398580935180/tmpobyegc", "state": "file", "uid": 0, "url": "https://toolbelt.treasuredata.com/sh/install-amazon2-td-agent4.sh"}
4

1 回答 1

1

基于"msg": "Destination /tmp/install-amazon2-td-agent4.sh is not writable",我猜是因为site.ymlcontainsbecome: yes语句,这使得所有任务都以root. “匿名”剧本不包含become:声明,因此需要一个来运行ansible-playbook --become或添加become: yes到它,也

ANSIBLE_ROLES_PATH="$(pwd)/roles" ansible-playbook "$@" /dev/stdin <<END
---
- hosts: $HOST_PATTERN
  become: yes
  roles:
    - $ROLE
END
于 2020-09-23T05:04:31.920 回答