ANSIBLE_ROLES_PATH 无法假定在 bash 脚本中获得正确的角色
ANSIBLE_ROLES_PATH cannot assume to get correct role in bash script
从Ansible: Can I execute role from command line?-
HOST_PATTERN=
shift
ROLE=
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"}
根据"msg": "Destination /tmp/install-amazon2-td-agent4.sh is not writable"
,我猜是因为site.yml
包含become: 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
从Ansible: Can I execute role from command line?-
HOST_PATTERN=
shift
ROLE=
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"}
根据"msg": "Destination /tmp/install-amazon2-td-agent4.sh is not writable"
,我猜是因为site.yml
包含become: 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