Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read ansible.cfg from project/current directory #302

Open
foto-andreas opened this issue Jul 23, 2024 · 11 comments
Open

read ansible.cfg from project/current directory #302

foto-andreas opened this issue Jul 23, 2024 · 11 comments

Comments

@foto-andreas
Copy link

Hi,

is this only a forgotten TODO or did you encounter problems implementing the usage of ansible.config in current directory?

64 | //TODO ansible.cfg (in the current directory)
65 |  
66 | // in the home directory
67 | getPasswordFilePathFromConfig(SystemProperties.getUserHome() + "/.ansible.cfg")

Andreas

@foto-andreas
Copy link
Author

Adding my idea:

    // in project directory
    for (p in ProjectManager.getInstance().openProjects) {
        for (r in ProjectRootManager.getInstance(p).contentRoots) {
            getPasswordFilePathFromConfig(r.path + "/ansible.cfg")
                ?.let { return r.path + "/" + it }
        }
        break;
    }

    // in current directory
    getPasswordFilePathFromConfig("ansible.cfg")
        ?.let { return File(it).absolutePath }

Beware. I have no idea on the correct IJ-APIs to use, but this solution works for me.

Open:

  • using projects[0] - is this correct when multiple projects are open. Should use the current project
  • is searching all content roots ok?
  • ...

Andreas

@foto-andreas
Copy link
Author

working on pull request #304 on it

@Grogdunn
Copy link

In our company we use to have all ansible files under subdirectory, this PR can support this?
Eg:

[root]/ansible/ansible.cfg
or
[root]/infrastructure/ansible/ansible.cfg

@foto-andreas
Copy link
Author

not currently, only if the vaulted files are also in that directory. how will ansible-playbook find these files when called?

@Grogdunn
Copy link

Grogdunn commented Aug 1, 2024

Simply we have a Makefile with a target like this:

deploy: build
	ANSIBLE_CONFIG=ansible/ansible.cfg ansible-playbook \
        --private-key ~/.ssh/superkey.pem \
        -i ansible/inventories/prod/hosts \
        --user admin \
        ansible/main.yml

or simple cd and execute the playbook

@foto-andreas
Copy link
Author

Ah, ANSIBLE_CONFIG environment variable. I think this is already supported. just place vault_password_file property in the ansible.cfg or set a second environment variable ANSIBLE_VAULT_PASSWORD_FILE to the password file path.

@Grogdunn
Copy link

Grogdunn commented Aug 1, 2024

How to configure IDEA with ANSIBLE_CONFIG? I don't know.

@foto-andreas
Copy link
Author

@sadv1r
Copy link
Owner

sadv1r commented Aug 7, 2024

How to configure IDEA with ANSIBLE_CONFIG? I don't know.

Hi 👋!

You can set an environment variable on the system level, like for the default tool.

@sadv1r
Copy link
Owner

sadv1r commented Aug 7, 2024

@foto-andreas, thanks for the issue. I really forgot about that to-do.

I'm trying to stick with the default locations from Ansible documentation, but even complex setups supported using a password file with a script, where we can do literally anything.

@Grogdunn
Copy link

Grogdunn commented Aug 7, 2024

How to configure IDEA with ANSIBLE_CONFIG? I don't know.

Hi 👋!

You can set an environment variable on the system level, like for the default tool.

Yes and no... Because I need to set multiple time environment variable (that is global) once for each project I open, and sometimes I open 2 to 4 projects, at same time, all with ansible inside (and a lot of other things), and sometimes ansible.cfg files are under a path or sometimes under some "funky" path. And cherry on the cacke, each project has a different vault password file.
So I can specify the ansible.cfg file position per project or can be done a sort of a discovery on project paths/index.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants