Skip to content

Conversation

@jdashton
Copy link
Contributor

@jdashton jdashton commented Jun 9, 2021

In some cases we may need to run this role against servers on which Apache httpd is disabled, or on which we want the initial state of the server to be disabled. This PR adds a variable that can be overridden when setting the enabled/disabled status of the Apache httpd service. The default value isenabled: yes, so there is no change to how this role has worked in the past. However, users can set this variable per host as needed.

Further, a pre_task can be used with code like the following to keep the current state of the service unchanged. This example assumes that the playbook changes the default values for both apache_state and apache_enabled, but demonstrates how to re-enable them if the service already existed on the box.

- name: Get service status on each host
  service_facts:
  tags: service_status

- set_fact:
    apache_state: "started"
  when:
    - "'httpd.service' in ansible_facts.services"
    - "'running' == ansible_facts.services['httpd.service'].state"
  tags: service_status

- set_fact:
    apache_enabled: "yes"
  when:
    - "'httpd.service' in ansible_facts.services"
    - "'enabled' == ansible_facts.services['httpd.service'].status"
  tags: service_status

@stale
Copy link

stale bot commented Sep 7, 2021

This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark pull requests as stale.

@stale stale bot added the stale label Sep 7, 2021
@jdashton
Copy link
Contributor Author

@geerlingguy, would you consider an enhancement like this?

@stale
Copy link

stale bot commented Sep 28, 2021

This issue is no longer marked for closure.

@stale stale bot removed the stale label Sep 28, 2021
@geerlingguy geerlingguy merged commit 0d5779e into geerlingguy:master Sep 28, 2021
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

Successfully merging this pull request may close these issues.

2 participants