4

I am new to Ansible. I have a bash script which has three arguments to be passed. I have to run this bash script on the remote server from Ansible.

Basically, I want to declare the hostname, duration and the comment fields as arguments while executing the Ansible command. I don't want to edit the file, as I am doing it from a Slack channel.

- hosts: nagiosserver

  tasks:
   - name: Executing a script
     command: sh /home/aravind/downtime.sh {hostname} {duration} {comments}
1
  • Welcome to Stack overflow could you please edit and add your sh file content Commented Jul 31, 2017 at 20:36

1 Answer 1

5

If you're executing ansible via ansible-playbook myplay.yml, you can pass additional variables via -e varname=varvalue. A lazy fix would be to run with

ansible-playbook myplay.yml -e my_hostname=foo -e my_duration=bar -e my_comments=foobar

But you should consider that the hostname is already defined in your inventory or gathered facts.

So you could update your playbook to use these additional variables using

- hosts: nagiosserver

  tasks:
    - name: Executing a script
    - command: "sh /home/aravind/downtime.sh {{my_hostname}} {{my_duration}} {{my_comments}}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.