mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
comment wordpress module
This commit is contained in:
parent
2659b8b03e
commit
947bb86695
5 changed files with 209 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Manage wordpress plugins
|
||||
This module is used to manage Wordpress installations
|
||||
|
||||
:depends: wp binary from http://wp-cli.org/
|
||||
'''
|
||||
import re
|
||||
import pprint
|
||||
|
@ -20,10 +22,23 @@ def __virtual__():
|
|||
def _get_plugins(stuff):
|
||||
return Plugin(stuff)
|
||||
|
||||
|
||||
def list_plugins(path, user):
|
||||
"""
|
||||
Check if plugin is activated in path
|
||||
"""
|
||||
'''
|
||||
List plugins in an installed wordpress path
|
||||
|
||||
path
|
||||
path to wordpress install location
|
||||
|
||||
user
|
||||
user to run the command as
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' wordpress.list_plugins /var/www/html apache
|
||||
'''
|
||||
ret = []
|
||||
resp = __salt__['cmd.shell']((
|
||||
'wp --path={0} plugin list'
|
||||
|
@ -34,6 +49,24 @@ def list_plugins(path, user):
|
|||
|
||||
|
||||
def show_plugin(name, path, user):
|
||||
'''
|
||||
Show a plugin in a wordpress install and check if it is installed
|
||||
|
||||
name
|
||||
Wordpress plugin name
|
||||
|
||||
path
|
||||
path to wordpress install location
|
||||
|
||||
user
|
||||
user to run the command as
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' wordpress.show_plugin HyperDB /var/www/html apache
|
||||
'''
|
||||
ret = {'name': name}
|
||||
resp = __salt__['cmd.shell']((
|
||||
'wp --path={0} plugin status {1}'
|
||||
|
@ -47,6 +80,24 @@ def show_plugin(name, path, user):
|
|||
|
||||
|
||||
def activate(name, path, user):
|
||||
'''
|
||||
Activate a wordpress plugin
|
||||
|
||||
name
|
||||
Wordpress plugin name
|
||||
|
||||
path
|
||||
path to wordpress install location
|
||||
|
||||
user
|
||||
user to run the command as
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' wordpress.activate HyperDB /var/www/html apache
|
||||
'''
|
||||
check = show_plugin(name, path, user)
|
||||
if check['status'] == 'active':
|
||||
# already active
|
||||
|
@ -62,6 +113,24 @@ def activate(name, path, user):
|
|||
|
||||
|
||||
def deactivate(name, path, user):
|
||||
'''
|
||||
Deactivate a wordpress plugin
|
||||
|
||||
name
|
||||
Wordpress plugin name
|
||||
|
||||
path
|
||||
path to wordpress install location
|
||||
|
||||
user
|
||||
user to run the command as
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' wordpress.deactivate HyperDB /var/www/html apache
|
||||
'''
|
||||
check = show_plugin(name, path, user)
|
||||
if check['status'] == 'inactive':
|
||||
# already inactive
|
||||
|
@ -77,6 +146,21 @@ def deactivate(name, path, user):
|
|||
|
||||
|
||||
def is_installed(path, user=None):
|
||||
'''
|
||||
Check if wordpress is installed and setup
|
||||
|
||||
path
|
||||
path to wordpress install location
|
||||
|
||||
user
|
||||
user to run the command as
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' wordpress.is_installed /var/www/html apache
|
||||
'''
|
||||
retcode = __salt__['cmd.retcode']((
|
||||
'wp --path={0} core is-installed'
|
||||
).format(path), runas=user)
|
||||
|
@ -86,6 +170,37 @@ def is_installed(path, user=None):
|
|||
|
||||
|
||||
def install(path, user, admin_user, admin_password, admin_email, title, url):
|
||||
'''
|
||||
Run the initial setup functions for a wordpress install
|
||||
|
||||
path
|
||||
path to wordpress install location
|
||||
|
||||
user
|
||||
user to run the command as
|
||||
|
||||
admin_user
|
||||
Username for the Administrative user for the wordpress install
|
||||
|
||||
admin_password
|
||||
Initial Password for the Administrative user for the wordpress install
|
||||
|
||||
admin_email
|
||||
Email for the Administrative user for the wordpress install
|
||||
|
||||
title
|
||||
Title of the wordpress website for the wordpress install
|
||||
|
||||
url
|
||||
Url for the wordpress install
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' wordpress.install /var/www/html apache dwallace password123 \
|
||||
dwallace@example.com "Daniel's Awesome Blog" https://blog.dwallace.com
|
||||
'''
|
||||
retcode = __salt__['cmd.retcode']((
|
||||
'wp --path={0} core install '
|
||||
'--title="{1}" '
|
|
@ -1,6 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Manage wordpress plugins
|
||||
This state module is used to manage Wordpress installations
|
||||
|
||||
:depends: wp binary from http://wp-cli.org/
|
||||
'''
|
||||
|
||||
|
||||
|
@ -8,7 +10,42 @@ def __virtual__():
|
|||
return 'wordpress.show_plugin' in __salt__
|
||||
|
||||
|
||||
def installed(name, path, user, admin_user, admin_password, admin_email, title, url):
|
||||
def installed(name, user, admin_user, admin_password, admin_email, title, url):
|
||||
'''
|
||||
Run the initial setup of wordpress
|
||||
|
||||
name
|
||||
path to the wordpress installation
|
||||
|
||||
user
|
||||
user that owns the files for the wordpress installation
|
||||
|
||||
admin_user
|
||||
username for wordpress website administrator user
|
||||
|
||||
admin_password
|
||||
password for wordpress website administrator user
|
||||
|
||||
admin_email
|
||||
email for wordpress website administrator user
|
||||
|
||||
title
|
||||
title for the wordpress website
|
||||
|
||||
url
|
||||
url for the wordpress website
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
/var/www/html:
|
||||
wordpress.installed:
|
||||
- title: Daniel's Awesome Blog
|
||||
- user: apache
|
||||
- admin_user: dwallace
|
||||
- admin_email: dwallace@example.com
|
||||
- admin_password: password123
|
||||
- url: https://blog.dwallace.com
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'comment': '',
|
||||
|
@ -25,7 +62,7 @@ def installed(name, path, user, admin_user, admin_password, admin_email, title,
|
|||
ret['comment'] = 'Wordpress will be installed: {0}'.format(name)
|
||||
return ret
|
||||
|
||||
resp = __salt__['wordpress.install'](path, user, admin_user, admin_password, admin_email, title, url)
|
||||
resp = __salt__['wordpress.install'](name, user, admin_user, admin_password, admin_email, title, url)
|
||||
if resp:
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Wordpress Installed: {0}'.format(name)
|
||||
|
@ -39,6 +76,25 @@ def installed(name, path, user, admin_user, admin_password, admin_email, title,
|
|||
|
||||
|
||||
def activated(name, path, user):
|
||||
'''
|
||||
Activate wordpress plugins
|
||||
|
||||
name
|
||||
name of plugin to activate
|
||||
|
||||
path
|
||||
path to wordpress installation
|
||||
|
||||
user
|
||||
user who should own the files in the wordpress installation
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
HyperDB:
|
||||
wordpress.activated:
|
||||
- path: /var/www/html
|
||||
- user: apache
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'comment': '',
|
||||
|
@ -77,6 +133,25 @@ def activated(name, path, user):
|
|||
|
||||
|
||||
def deactivated(name, path, user):
|
||||
'''
|
||||
Deactivate wordpress plugins
|
||||
|
||||
name
|
||||
name of plugin to deactivate
|
||||
|
||||
path
|
||||
path to wordpress installation
|
||||
|
||||
user
|
||||
user who should own the files in the wordpress installation
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
HyperDB:
|
||||
wordpress.deactivated:
|
||||
- path: /var/www/html
|
||||
- user: apache
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'comment': '',
|
|
@ -1,6 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Test wrapper for running all KitchenSalt tests
|
||||
|
||||
All directories in 'tests/kitchen/' will be treated as a separate test under
|
||||
the KitchenTestCase.
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
def test_formula(salt):
|
||||
'''
|
||||
Test that the states are synced to minion
|
||||
'''
|
||||
dirs = salt('cp.list_master_dirs')
|
||||
assert 'states' in dirs
|
||||
|
||||
def test_wordpress_module(salt):
|
||||
'''
|
||||
Test that the wordpress dir grain was set on the minion
|
||||
'''
|
||||
wordpressdir = salt('grains.get', 'wordpressdir')
|
||||
assert salt('wordpress.is_installed', wordpressdir)
|
||||
|
|
|
@ -2,5 +2,8 @@ import requests
|
|||
|
||||
|
||||
def test_server(host_ip, http_port):
|
||||
'''
|
||||
Test that wordpress was setup on the minion correctly and returns a 200 after being installed
|
||||
'''
|
||||
resp = requests.get('http://{0}:{1}'.format(host_ip, http_port), headers={'Host': 'blog.manfred.io'})
|
||||
assert resp.status_code == 200
|
||||
|
|
Loading…
Add table
Reference in a new issue