ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
834 stars 1.54k forks source link

module to gather facts about apache2/httpd config #3664

Open Kariton opened 3 years ago

Kariton commented 3 years ago

Summary

Im looking for a way to gather information about the present httpd configuration. Like one of the *_info modules. (mysql, mongodb, firewalld, listen_port etc.)

i came across this two already existing scripts: https://github.com/domcar/apache-config https://github.com/etingof/apacheconfig

in my case an json from apachectl -S / httpd -S would be sufficient.

some example json ```yml { "VirtualHost": [ { "app3.com": [ { "listen_address": "172.27.10.57", "listen_port": 443, "config": "/etc/httpd/conf.d/04-app3.conf", "row": 27 } ] }, { "app2.de": [ { "listen_address": "172.27.10.59", "listen_port": 443, "config": "/etc/httpd/conf.d/02-app2.conf", "row": 27 } ] }, { "app4.nl": [ { "listen_address": "172.27.10.58", "listen_port": 443, "config": "/etc/httpd/conf.d/02-app4.conf", "row": 27 } ] }, { "172.27.10.49:443": [ { "default": [ { "server": "www-app1.example.com", "config": "/etc/httpd/conf.d/01-www-app1.conf", "row": 22 } ], "port 443": [ { "namevhost": "www-app1.example.com", "config": "/etc/httpd/conf.d/01-www-app1.conf", "row": 22 }, { "namevhost": "www-app1nl.example.com", "config": "etc/httpd/conf.d/02-www-app1nl.conf", "row": 22 } ] } ] }, { "*:80": [ { "default": [ { "server": "www-app1.example.com", "config": "/etc/httpd/conf.d/01-www-app1.conf", "row": 22 } ] } ] }, { "ServerRoot": "/etc/httpd", "Main DocumentRoot": "/etc/httpd/htdocs", "Main ErrorLog": "/etc/httpd/logs/error_log", "Mutex authn-socache": "using_defaults", "Mutex ssl-cache": "using_defaults", "Mutex default": [ { "dir": "/run/httpd/", "mechanism": "default" } ], "Mutex mpm-accept": "using_defaults", "Mutex authdigest-opaque": "using_defaults", "Mutex proxy-balancer-shm": "using_defaults", "Mutex rewrite-map": "using_defaults", "Mutex authdigest-client": "using_defaults", "Mutex ssl-stapling": "using_defaults", "Mutex proxy": "using_defaults", "PidFile": "/run/httpd/httpd.pid", "Define": [ "_RH_HAS_HTTPPROTOCOLOPTIONS", "DUMP_VHOSTS", "DUMP_RUN_CFG" ], "User": [ { "name": "apache", "id": 48 } ], "Group": [ { "name": "apache", "id": 48 } ] } ] } ``` or like that - there is maybe a better structure.

Issue Type

Feature Idea

Component Name

apache2_info

Additional Information

- name: Gather facts from apache2/httpd configuration.
  community.general.apache2_info:

Code of Conduct

ansibullbot commented 3 years ago

Files identified in the description: None

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

russoz commented 3 years ago

hi @Kariton thanks for submitting this issue.

This problem is actually less simple than it seems. Per your example I take it you are using a rpm-based distro, but if you were in a deb-based one the paths would be more like /etc/apache2/* and the directory structure is completely different. I have no idea how that goes in MacOS and/or FreeBSD, but I risk saying it must be even different.

One possible strategy is to make the new module rpm-only at first, then expand it to other platforms over time.

Kariton commented 3 years ago

Hey @russoz,

Yes - im on a RHEL based system. :) I tested https://github.com/domcar/apache-config a bit more - seems to work mostly fine. On RHEL at least.

I noticed a little bug that i will try to debug. https://github.com/domcar/apache-config/issues/1

It even looks to me like he does handle ubuntu within his script as well.

    global apache_dir
    if platform.dist()[0] == 'Ubuntu':
       apache_dir = '/etc/apache2/'
       input_file = open (apache_dir+'apache2.conf','r')
    else:
       apache_dir = '/etc/httpd/'
       input_file = open (apache_dir+'conf/httpd.conf','r')

For me and my newbie eyes it looks very promising. anyway i can say nothing about the JSON structure itself - for now. But there is a massive amount of information in there.

I think the modification to work as an ansible module itself are not that big. compatibility is another thing. will try that further. (would be more of a first time python experience...)

Kariton commented 3 years ago

ether way - apachectl -S / httpd -S should work on any (?) OS type.

so that way it would at least print facts about:

Show the settings as parsed from the config file (currently only shows the virtualhost settings).

and IMO this is the most important fact. and would be exactly what i was initially looking for.

Kariton commented 3 years ago

just for clarification:

the discovered script https://github.com/domcar/apache-config does parse the default apache2 / httpd config INCL. all included files. It basically follows the hole configuration with every aspect of it. The README.MD explains that nicely.

i just "needed" the running vhost configs incl. listen IP / Port / ServerName

russoz commented 3 years ago

@Kariton I hadn't looked into that script before. It does look interesting. Would you like to submit the new module? We would be more than happy to assist you through the process. The first thing you would need is to read https://github.com/ansible-collections/community.general/blob/main/CONTRIBUTING.md and I also suggest you take a look other modules.