0
votes

Here is the inventory content:

[osm]
osm_host ansible_port=22 ansible_host=10.20.20.11 ansible_user=ubuntu ansible_ssh_private_key_file=/path/to/key/key

And here is the playbook content:

- hosts: osm
  user: ubuntu
  become: yes
  tasks:
    - name: Download the OSM installer
      get_url: url=https://osm-download.etsi.org/ftp/osm-8.0-eight/install_osm.sh dest=/tmp/install_osm.sh
    - name: Execute the OSM installer
      shell: /tmp/install_osm.sh

When I run ansible-playbook -i inventory play.yaml, I get the following error:

PLAY [osm]


TASK [Gathering Facts] ********************************************************* ok: [osm_host]

TASK [Download the OSM installer] ********************************************** ok: [osm_host]

TASK [Execute the OSM installer] *********************************************** fatal: [osm_host]: FAILED! => {"changed": true, "cmd": "/tmp/install_osm.sh", "delta": "0:00:00.001919", "end": "2020-09-04 19:26:46.510381", "msg": "non-zero return code", "rc": 126, "start": "2020-09-04 19:26:46.508462", "stderr": "/bin/sh: 1: /tmp/install_osm.sh: Permission denied", "stderr_lines": ["/bin/sh: 1: /tmp/install_osm.sh: Permission denied"], "stdout": "", "stdout_lines": []}

PLAY RECAP ********************************************************************* osm_host : ok=2 changed=0 unreachable=0
failed=1 skipped=0 rescued=0 ignored=0

I tried to use true and yes for the become clause, but nothing changed. What am I missing?

1

1 Answers

1
votes

You have to be sure that the root user has executable permissions on the new OSM download. When you use a become: yes without become_user, the default user is root So you need to be sure that root user can execute your script.

Try the get_url like that:

- hosts: osm
  user: ubuntu
  become: yes
  tasks:
    - name: Download the OSM installer
      get_url: 
        url: https://osm-download.etsi.org/ftp/osm-8.0-eight/install_osm.sh 
        dest: /tmp/install_osm.sh
        mode: "0555"
    - name: Execute the OSM installer
      shell: /tmp/install_osm.sh

Play with the mode param of the get_url module.