Don't forget shebang when writing Check! Ansible's Dynamic Inventory in python!

Hello, this is @dz_ this and Ohira Kazumi.

Prologue-Introduction

For configuration management, I prefer Ansible. This time, I wanted to specify the inventory dynamically, so when I tried Dynamic Inventory ... I got stuck in the following error for a while. I was able to deal with it, so write down the memorandum.

For Dynamic Inventory, I referred to the following documents.

Don't forget shebang when writing Ansible's Dynamic Inventory in python!

error contents

Here is the error I encountered.

ERROR! Attempted to execute "./dynamic-inventory.py" as inventory script: problem running ./dynamic-inventory.py --list ([Errno 8] Exec format error)
Attempted to read "./dynamic-inventory.py" as ini file: ./dynamic-inventory.py:1: Expected key=value host variable assignment, got: 

"I tried to run the script, but I got an error. I also read it as an ini file, but it doesn't work."

Coping

After a lot of trial and error, I found this issue!

That file needs a shebang line.

I see, I need a shebang line! shebang?

-Shebang (Unix)-Wikipedia

A shebang or shebang is the first line of a UNIX script that starts with # !.

I see! !!

So, referring to Python's Shebang line, if you write the following shebang in my operating environment It looks good.

#!/usr/bin/env python

When I set this, it worked smoothly! (・ Ε ・;)

Epilogue-Conclusion

Shebang didn't usually care so much, so it was an unexpected pitfall!

Recommended Posts

Don't forget shebang when writing Check! Ansible's Dynamic Inventory in python!
When writing a program in Python
[Tips] Easy-to-read writing when connecting functions in Python
Split files when writing vim plugin in python
A memorandum when writing experimental code ~ Logging in python
Master the type in Python? (When should type check be done)
Convenient writing method when appending to list continuously in Python
Don't make test.py in Python!
[Python ORM] Notation when writing SQL using subquery in IN clause in SQLAlchemy
Check for memory leaks in Python
Check for external commands in python
Precautions when using pit in Python
Check the behavior when assigning Python
Check and move directories in Python
When using regular expressions in Python
What Emacs users should know when writing python code in Sublime Text