Git Product home page Git Product logo

Comments (12)

JoshuaLyle avatar JoshuaLyle commented on July 18, 2024

Nevermind. I didn't realize that the module wrappers in library/ were what properly call and exit the actual modules in module_utils. Placing the library/ folder in the top level of my project folder caused ansible to use the proper wrapper module from library/ so that it operated correctly.

I might suggest renaming the modules in module_utils/network/pfsense and changing the associated imports in library/ wrappers so that they don't have the same names as the wrappers that the user interacts with. That way, ansible doesn't accidentally call the module_utils file directly resulting in an improper exit I mentioned above.

from ansible-pfsense.

f-bor avatar f-bor commented on July 18, 2024

I'm not sure to understand well your issue.

At first, you have copied our files into your ansible installation ?

from ansible-pfsense.

JoshuaLyle avatar JoshuaLyle commented on July 18, 2024

Yes I did.

First, I copied module_utils/network/pfsense into /usr/local/lib/python3.6/dist-packages/ansible/module_utils/network/

When I reference pfsense_interface or any other pfsense_* module from this project, ansible looks in /usr/local/lib/python3.6/dist-packages/ansible/module_utils/network/pfsense for the module matching that name.

When I tried to run pfsense_interface from a playbook, it tried executing /usr/local/lib/python3.6/dist-packages/ansible/module_utils/network/pfsense/pfsense_interface.py but I got the error "msg": "New-style module did not handle its own exit".

It wasn't clear to me that I needed to copy library into my local directory so that ansible would use
./library/pfsense_interface.py
instead of
/usr/local/lib/python3.6/dist-packages/ansible/module_utils/network/pfsense/pfsense_interface.py which is necessary because
./library/pfsense_interface.py properly instantiates PFSenseInterfaceModule and properly exits with exit_json() when it gets called with pfmodule.commit_changes()

I'm simply saying it's an easy mistake to make since both files are named pfsense_interface.py and both would be included in ansible's module path when executing it even though /usr/local/lib/python3.6/dist-packages/ansible/module_utils/network/pfsense/pfsense_interface.py isn't supposed to be used directly.

I hope that makes some sense. I can try to clarify more if you want me to.

from ansible-pfsense.

f-bor avatar f-bor commented on July 18, 2024

Ok.

In my opinion, you should install all our files in one place, either in your local directory, either in your ansible installation.

The best would be your local installation.

If for any reason you prefer to use your ansible installation, we have wrote a script that copy all required files into the ansible directory (just run ./misc/local2ansible). It was written because we need to have our files into ansible to use their testing and linting tools.

Could you check there is not a pfsense/networking directory that would still be around in your directories ? (we had to rename it to pfsense/network at a time, and it may explain your issue)

Please let me know if you choose to use your ansible directory, so that I manage files/directories renaming in the install script.

from ansible-pfsense.

JoshuaLyle avatar JoshuaLyle commented on July 18, 2024

so I took a look at /misc/local2ansible and there are two lines that confuse me

cp module_utils/network/pfsense/*.py ${ANSIBLE_HOME}/lib/ansible/module_utils/network/pfsense/
cp library/*.py ${ANSIBLE_HOME}/lib/ansible/modules/network/pfsense/

It confuses me because there files in module_utils/network/pfsense/ and library/ that are named the same thing so running this script would result in files being copied and then immediately overwritten such as

  • pfsense_haproxy_backend.py
  • pfsense_haproxy_backend_server.py
  • pfsense_interface.py
  • pfsense_ipsec.py
  • pfsense_ipsec_p2.py
  • pfsense_ipsec_proposal.py
  • pfsense_nat_outbound.py
  • pfsense_nat_port_forward.py
  • pfsense_rule.py
  • pfsense_vlan.py

So the only way I can get this repo to work correctly is to copy library/ into whatever folder I'm working on and then copy the contents of ./module_utils/network/pfsense into /usr/local/lib/python3.6/dist-packages/ansible/module_utils/network/pfsense/

Doing that will make ansible use ./library/pfsense_* modules when calling them from my playbook and then those files in ./library/pfsense_* can properly import the classes from the python library files I copied into /usr/local/lib/python3.6/dist-packages/ansible/module_utils/network/pfsense/ with lines such as
from ansible.module_utils.network.pfsense.pfsense_interface import PFSenseInterfaceModule, INTERFACE_ARGUMENT_SPEC, INTERFACE_REQUIRED_IF found in ./library/pfsense_interface.py`

from ansible-pfsense.

f-bor avatar f-bor commented on July 18, 2024

You're making a mistake. The two target directories are differents and have different purpose:

${ANSIBLE_HOME}/lib/ansible/module_utils/network/pfsense/
${ANSIBLE_HOME}/lib/ansible/modules/network/pfsense/

The first one is for imports needed by the modules.
The second one is for the modules themself.

from ansible-pfsense.

JoshuaLyle avatar JoshuaLyle commented on July 18, 2024

I must've misread it, I'll try again tomorrow and let you know.

from ansible-pfsense.

JoshuaLyle avatar JoshuaLyle commented on July 18, 2024

Do you have an example of what ${ANSIBLE_HOME} should be?

I cannot find the expected file layout anywhere in ansible 2.9.2. I guessed that ANSIBLE_HOME should've been in /usr/local/lib/python3.6/dist-packages/ansible but running find . | grep lib/ to try to find the lib folder that local2ansible copies the files into shows no directory existing named lib

from ansible-pfsense.

f-bor avatar f-bor commented on July 18, 2024

It was designed to install our files into the source folder.

I did what was required in the last commit to detect the right path and to do the install there.

from ansible-pfsense.

opoplawski avatar opoplawski commented on July 18, 2024

FWIW - I think it probably does make sense to rename the pfsense_* files/classes in module_utils by removing the "pfsense_" prefix.

from ansible-pfsense.

f-bor avatar f-bor commented on July 18, 2024

I dont have any opinion on this so sure, why not ? :)

from ansible-pfsense.

JoshuaLyle avatar JoshuaLyle commented on July 18, 2024

I think merging #38 means this is good to close?

from ansible-pfsense.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.