# Creating yaml script to be executed in bash

**URL:** <https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808>\
**Category:** Ansible Project\
**Created:** [June 16, 2018, 9:28am UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808 "2018-06-16T09:28:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vamsi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/v/a8b319/32.png) [@Vamsi\_Krishna](https://forum.ansible.com/u/Vamsi_Krishna)\
**Post date:** [June 16, 2018, 9:28am UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/1 "2018-06-16T09:28:26Z")

</div>

HI All,

I have written a yaml script in bash shell as below but no met with success, Request your help

[root@ tmp]# cat /root/pay.sh

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [June 16, 2018, 1:13pm UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/2 "2018-06-16T13:13:46Z")

</div>

It looks to me as if you have several very fundamental misunderstandings about Ansible, bash and yaml.

However:

- bash is a shell scripting language. Bash scripts generally start with #!/bin/bash

- yaml is a serialisation language, generally used to describe data

- Ansible reads yaml descriptions of things and attempts to make them

So to create your file via yaml and Ansible, as it seems you are trying to do, you would:

- rename /root/pay.sh to /root/pay.yaml

- run ansible-playbook /root/pay.yaml

You don’t HAVE to give your yaml files a “.yaml” extension, but you will avoid a lot of confusion if you do.

Your yaml code has at least one error, in that the stanza does not start with a dash. It should read:

---

<div class="post-metadata">

**Author:** ![Vamsi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/v/a8b319/32.png) [@Vamsi\_Krishna](https://forum.ansible.com/u/Vamsi_Krishna)\
**Post date:** [June 17, 2018, 6:18am UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/3 "2018-06-17T06:18:48Z")

</div>

HI Karl,

Thanks for the reviewing it. Basically we dont have ansible master in our environment instead there is HP automation tool in place. All I am looking, is there any possibility of writing yaml scripts that can be directly executed over bash shell without having ansible server ?

I have knowledge on bash shell scripting and looking for yaml. Request you to provide any reference link on how can yaml be executed on bash if possbile

Thanks

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [June 17, 2018, 6:26am UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/4 "2018-06-17T06:26:44Z")

</div>

In Unix, it’s rare that something is outright impossible, but sometimes the effort outweighs any benefit 🙂

As far as I know, yaml is not a command shell. It is not designed to do things, it is designed to describe things. It needs to be processed by another tool, such as Ansible.

It’s hard to be sure, but I suspect that you are trying to use the wrong tool. Why do you think you need to “run” yaml code?

---

<div class="post-metadata">

**Author:** ![Adam\_Lanier](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@Adam\_Lanier](https://forum.ansible.com/u/Adam_Lanier)\
**Post date:** [June 17, 2018, 7:33pm UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/5 "2018-06-17T19:33:17Z")

</div>

To put it another way, Yaml is not a scripting language. You can’t write yaml scripts. Yaml, used in conjunction with Ansible, is a declarative description of a desired state.

You can use Ansible to execute your Yaml statements to bring your environment to the desired state. There is no Ansible server required. And, unless you count Tower/AWX, there is no such thing as an Ansible server.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 18, 2018, 2:32pm UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/6 "2018-06-18T14:32:08Z")

</div>

Just to give an example of what Adam is saying above, you cannot  
execute .xml or .csv or .gif scripts, they are data formats.

---

<div class="post-metadata">

**Author:** ![mhalano](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mhalano/32/1815_2.png) [@mhalano](https://forum.ansible.com/u/mhalano)\
**Post date:** [June 18, 2018, 2:35pm UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/7 "2018-06-18T14:35:09Z")

</div>

I think you can’t either execute a .yaml file because it’s just have data. You can use a special defined .yaml to be pass instructions to be executed by Ansible, but you can’t execute just the .yaml file. I think that’s the point of the question.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 18, 2018, 2:41pm UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/8 "2018-06-18T14:41:01Z")

</div>

You CAN make the .yaml/.yml file executable (permissions) and add an  
ansible shebang:

#!/usr/bin/env ansible-playbook

to the top of the file, this is how most scripting languages work, its  
just not a YAML script, its an Ansible one.

---

<div class="post-metadata">

**Author:** ![mhalano](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mhalano/32/1815_2.png) [@mhalano](https://forum.ansible.com/u/mhalano)\
**Post date:** [June 18, 2018, 2:56pm UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/9 "2018-06-18T14:56:04Z")

</div>

Yeah, but you need Ansible installed. .yaml files has no native interpreter (different from shell scripts, for instance).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 18, 2018, 2:58pm UTC](https://forum.ansible.com/t/creating-yaml-script-to-be-executed-in-bash/27808/10 "2018-06-18T14:58:49Z")

</div>

All scripts need an interpreter installed, in this case the  
interpreter is `ansible-playbook`.

To have an executable w/o requiring an interpreter you need a binary.
