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
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
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:
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
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?
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.
Just to give an example of what Adam is saying above, you cannot
execute .xml or .csv or .gif scripts, they are data formats.
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.
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.
Yeah, but you need Ansible installed. .yaml files has no native interpreter (different from shell scripts, for instance).
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.