Skip to content

Instantly share code, notes, and snippets.

@cuongnv23
Last active March 28, 2018 19:00
Show Gist options
  • Select an option

  • Save cuongnv23/fb77bae3b6b013eb8d60 to your computer and use it in GitHub Desktop.

Select an option

Save cuongnv23/fb77bae3b6b013eb8d60 to your computer and use it in GitHub Desktop.
Ansible - Insert to end of line with lineinfile module
#handlers/main.yml
---
- name: Restart apache
service: name=apache2 state=restarted enabled=yes
tags:
- apache
#task/main.yml
---
- name: Enable apache modules
lineinfile: >
dest="{{ apache_sysconfig }}"
backrefs=true
state=present
regexp='^APACHE_MODULES=\"(.*(?<!{{ apache_en_modules }}))\"'
line='APACHE_MODULES="\1 {{ apache_en_modules }}"'
notify:
- Restart apache
tags:
- apache
- name: Add SSL to APACHE_SERVER_FLAGS
lineinfile: >
regexp='^APACHE_SERVER_FLAGS=\"(.*(?<!SSL))\"'
line='APACHE_SERVER_FLAGS="\1 SSL"'
dest="{{ apache_sysconfig }}"
backrefs=true
state=present
notify:
- Restart apache
tags:
- apache
#vars/main.yml
---
apache_sysconfig: "/etc/sysconfig/apache2"
apache_en_modules: "proxy proxy_http rewrite headers"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment