Getting started with a goal

New to the sysadmin world and learning Ansible on the job so I can assist with building a web cluster for our static sites that we host for some grandfather'd clients.

I think I have everything specified in the right place but I'm getting a permissions error when attempting to run the playbook and I'm not sure on the syntax for defining the variables when calling the playbook.

Thanks for reading and sorry about beginner mistakes.

command:

  • ansible-playbook -K pb-testing.yml --extra-vars:SITE=site.com

Here's what I have so far:

etc/ansible/playbook.yml


  • hosts: centos

    become: true

    gather_facts: no

    vars:

    site: "{{ SITE|default('null') }}"

    roles:

    • testing

ansible/roles/playbook/tasks/main.yml


  • hosts: centos

    become: true

    gather_facts: no

    vars:

    site: "{{ SITE|default('null') }}"

    roles:

    • testing
  • name: "Copying Script"

    copy:

    src: /etc/ansible/roles/move-site/tasks/download-site.sh

    dest: (direct path)/download-site.sh

    owner: ansible-user

    group: ansible-user

    mode: 0644

  • name: "Migrate Site"

    shell: download-site.sh

error: fatal: [192.168.16.112]: FAILED! => {"changed": true, "cmd": "download-site.sh", "delta": "0:00:00.016276", "end": "2017-08-29 11:17:03.146423", "failed": true, "rc": 126, "start": "2017-08-29 11:17:03.130147", "stderr": "/bin/sh: download-site.sh: Permission denied", "stderr_lines": ["/bin/sh: download-site.sh: Permission denied"], "stdout": "", "stdout_lines": []} to retry, use: --limit @/etc/ansible/pb-testing.retry

Posted Aug 29, 2017, 3:17 PM UTC · edited

14

Shell task should look like this:

- name: Migrate Site
  shell: download-site.sh
  args:
     chdir: /wherever

Also... a little obvious, but... is the download-site.sh file set to executable?

2
cubliclemonkeyOP•

Thanks. This is running on CentOS 7 server - no gui. Would it need to be set to executable for Ansible to use the .sh file?

1

If the file is being invoked as a file and not being passed directly to a shell binary, it would need its permissions set to allow execution by a non-root user, yes. If you're running the task using become: True, though, then I believe Ansible will be able to execute it regardless. Not 100% on that, though.

2
cubliclemonkeyOP•

I rearranged the entire thing:

  • Put the vars in vars/main.yml

  • Didn't call a bash file put the entire command in the playbook with 'shell:'.

I was also able to set my variables with '-e key=value'.

Thanks!

1