When executing a playbook with the following command I get a failed with a Could not find or access '/opt/ansible-automation-platform-setup-bundle-2.4-1.4-x86_64/setup.sh' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option
ansible-playbook playbooks/install_aap_platform.yml -f 10 -vvv --private-key $ID_RSA -u ec2-user -i installer_node
This is the ansible playbook:
- name: install ansible
hosts: installnode
become: yes
become_user: ansible
gather_facts: yes
tasks:
- name: populate /etc/hosts file
ansible.builtin.shell: |
cat {{ lookup('env', 'ANSIBLE_INSTALLER_LOCATION') }}/inventory | grep ".med.ds.osd.mil*" | awk '{print $1}' > test.txt
for i in $(cat test.txt); do
echo $i
if grep -q "$(echo "$i")" /etc/hosts ; then
echo "hostname $host_name already in hosts file"
else
echo $(echo $i | cut -d'.' -f1 | sed 's/ip-//' | sed 's/-/./g')" $i" >> /etc/hosts
fi
done
cat /etc/hosts
become: yes
become_user: root
- name: Run installer script
become: yes
become_user: ansible
ansible.builtin.script:
cmd: /opt/ansible-automation-platform-setup-bundle-2.4-1.4-x86_64/setup.sh
environment:
ANSIBLE_BECOME_METHOD: 'sudo'
ANSIBLE_BECOME: True
ANSIBLE_HOST_KEY_CHECKING: False
register: out
ignore_errors: yes
- name: print output
debug:
msg: "{{ out.stdout }}"
populate /etc/hosts file works without any issue, it is the task Run installer script that fails.
The task fails because it is not able to reach the file /opt/ansible-automation-platform-setup-bundle-2.4-1.4-x86_64/setup.sh, but if I ssh into the host and paste /opt/ansible-automation-platform-setup-bundle-2.4-1.4-x86_64/setup.sh and press enter, it works right away.
The script does not seem to be the issue, the folder /opt is owned by root, but the folder ansible-automation-platform-setup-bundle-2.4-1.4-x86_64/ is owned by the user ansible. I know that the become_user works because I used it in a previous task to upload files to the host system without any issues.
ansibleuser, right ?