# setuptools automatic script creation

**URL:** <https://forum.ansible.com/t/setuptools-automatic-script-creation/17988>\
**Category:** Ansible Developer\
**Created:** [April 15, 2015, 10:03pm UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988 "2015-04-15T22:03:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loren\_Carvalho](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Loren\_Carvalho](https://forum.ansible.com/u/Loren_Carvalho)\
**Post date:** [April 15, 2015, 10:03pm UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988/1 "2015-04-15T22:03:12Z")

</div>

Yeah, this old chestnut.

So I was working on packaging Ansible for distribution @ my job and I was reminded about this PR I submitted a while back:

[Leveraging setuptools automatic script creation by lorencarvalho · Pull Request #10122 · ansible/ansible · GitHub](https://github.com/ansible/ansible/pull/10122), the key takeaway being: [ansible/setup.py at bf6b43dd71a29e3c2a44fd425cf36c0528f40cc7 · lorencarvalho/ansible · GitHub](https://github.com/sixninetynine/ansible/blob/bf6b43dd71a29e3c2a44fd425cf36c0528f40cc7/setup.py)

As per the PR and links in the PR, this was going to be considered in V2, but there seemed to be some hesitation on testing/usefulness. I wanted to open a dialog on the usefulness by offering an example:

In my environment, we have an inventory system that requires results to be scoped based on a query language (real world example: %datacenter.servicename.instancenumber), so our dynamic inventory script requires some environment variables to be set (we use the host-pattern). I want my team and myself to be able to use Ansible as close to upstream as possible (if not pure ansible codebase, then at least usage matching that of the documentation). In order to achieve this we’ve done a few workarounds:

1. ansible () {
2. env ANSIBLE\_QUERY\_TYPE=host ANSIBLE\_QUERY=$1 $(/usr/bin/which ansible) “$@”
3. }

Or adding a header to all the bin/ansible\* scripts that patches via os.environ.update():

`  
∴ ld ~/src/ansible-ull\_trunk $ head bin/ansible  
#!/usr/bin/env python

# before official ansible, we patch the users env

from linkedin.ansibleull.header import env\_init  
env\_init()

---

<div class="post-metadata">

**Author:** ![Loren\_Carvalho](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Loren\_Carvalho](https://forum.ansible.com/u/Loren_Carvalho)\
**Post date:** [April 24, 2015, 4:41am UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988/2 "2015-04-24T04:41:40Z")

</div>

bump 🙂

---

<div class="post-metadata">

**Author:** ![Greg\_DeKoenigsberg1](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@Greg\_DeKoenigsberg1](https://forum.ansible.com/u/Greg_DeKoenigsberg1)\
**Post date:** [April 24, 2015, 2:45pm UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988/3 "2015-04-24T14:45:36Z")

</div>

So here’s my question:

Anyone else need this?

I hesitate to say “HEY LET’S VOTE” but it would be good to get a sense that others might find this useful.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [April 24, 2015, 3:10pm UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988/4 "2015-04-24T15:10:12Z")

</div>

Not needing it atm, but imho it would be a good practice to do that.

A next step would then be to use a bit more functions in the cli/ modules.

People wanting to write a custom wrapper script will then be able to maintain that more easily.

Serge

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [April 25, 2015, 11:20am UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988/5 "2015-04-25T11:20:22Z")

</div>

Oops, originally sent this just to loren. Forwarding to ansible-devel now 🙂

---

<div class="post-metadata">

**Author:** ![Loren\_Carvalho](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Loren\_Carvalho](https://forum.ansible.com/u/Loren_Carvalho)\
**Post date:** [April 25, 2015, 5:48pm UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988/6 "2015-04-25T17:48:35Z")

</div>

Cool! I actually like the sound of this more 🙂

It would be a good opportunity to standardize the option parsing between the scripts too (ansible using the ‘Cli’ object vs ansible-playbook using main(), etc)

---

<div class="post-metadata">

**Author:** ![Loren\_Carvalho](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Loren\_Carvalho](https://forum.ansible.com/u/Loren_Carvalho)\
**Post date:** [April 30, 2015, 2:40am UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988/7 "2015-04-30T02:40:22Z")

</div>

Hey Toshio,

I hacked on this a bit this weekend but my 8 month old distracted me before I could get anything of value – then earlier today I noticed in the v2 todo doc that James posted there was this note:

- Move to classes, generalize code

Does this mean any work here would be redundant?

thanks

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [April 30, 2015, 3:21pm UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988/8 "2015-04-30T15:21:24Z")

</div>

Not redundant necessarily, but it's on the roadmap... bcoca has been  
doing some work on this in the last few days:  
[https://github.com/ansible/ansible/pull/10885](https://github.com/ansible/ansible/pull/10885)

but it doesn't go as far as I think you were hoping for. His tree is  
pulling code into classes, the step that would get to where you want  
would be to push all of those classes into a new module (something  
like v2/ansible/cli/{\_\_init\_\_.py, galaxy.py, ad\_hoc.py, playbook.py,  
vault.py} ). Talking to bcoca about what he's working on would  
definitely be fruitful.

-Toshio

---

<div class="post-metadata">

**Author:** ![Loren\_Carvalho](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Loren\_Carvalho](https://forum.ansible.com/u/Loren_Carvalho)\
**Post date:** [May 2, 2015, 3:03am UTC](https://forum.ansible.com/t/setuptools-automatic-script-creation/17988/9 "2015-05-02T03:03:57Z")

</div>

Hey, just took a gander at the ansible.ansible.cli module and it’s actually exactly what I want!

Just gotta wait until v2 and I’ll be a happy camper!
