Hello folks!
I’m creating an Action plugin to query a file for contents.
I aim to publish it at Ansible Galaxy for myself to use, and perhaps it will be useful for someone else as well. It’s my first Ansible plugin, and it’s been a couple of years since I last touched Python as well, so I am in need of some guidance.
I have this file tree:
ansible_collections/
└── myns
└── query_file
├── galaxy.yml
├── LICENSE
├── meta
│ └── runtime.yml
├── plugins
│ ├── action
│ │ ├── args.json
│ │ ├── query
│ │ │ ├── config.py
│ │ │ ├── parse.py
│ │ │ ├── parse_target_container.py
│ │ │ ├── select_columns.py
│ │ │ ├── target_from.py
│ │ │ ├── target.py
│ │ │ ├── test_parse_dict.py
│ │ │ ├── test_parse_list.py
│ │ │ ├── test_parse.py
│ │ │ ├── test_parse_target_container.py
│ │ │ ├── test_select_columns.py
│ │ │ ├── test_shared.py
│ │ │ ├── test_target_from_string.py
│ │ │ ├── test_target_init.py
│ │ │ └── test_target_match_in.py
│ │ └── query_file.py
│ └── README.md
├── README.md
├── requirements.txt
└── tests
├── integration
│ ├── inventory
│ └── targets
│ └── action_query_file
│ └── tasks
│ └── test_x.yml
└── unit
└── plugins
└── action
└── test_y.py
-
query_file.py contains my class which extends ActionBase. I use some more modern stuff like types, @singledispatch, and @dataclass. I think it will be hard to support Python 2.7 so I thought I’d stick with Python 3 only. Does that decision make sense? I thought so since it’s been a while now since Python 2.7 become unsupported.
-
If I go for Python 3 only, is there something I should do for ansible-test sanity to pass? It complains about some missing Python versions.
-
Next to as a sibling to query_file.py I have a directory named query. It contains the generic logic which is pure Python and does not require Ansible. I’d like to keep that code split up as it is. Is there a better, more “standard”, place for it?
-
The query directory contains tests as well. I like my tests next to the files being tested, but it seems Ansible prefers a tests directory. Should I move my tests there for them to be executed well in a pipeline?
Thank you very much for taking the time to read this far! I hope there are some knowledgable people here who can provide some answers.
/ Kent