data_source_description
stringclasses
1 value
input
stringlengths
19
21.6k
license
stringclasses
1 value
module
stringclasses
219 values
output
stringlengths
2
4.69k
path
stringlengths
8
110
repo_name
stringclasses
9 values
repo_url
stringclasses
12 values
--- - name: set fact change_api_password to false set_fact: change_api_password=false - name: set fact manage_native_users to false set_fact: manage_native_users=false - name: set fact manage_native_users to true set_fact: manage_native_users=true when: es_users is defined and es_users.native is defined and es_users.native.keys() | list | length > 0 - name: set fact manage_native_role to false set_fact: manage_native_roles=false - name: set fact manage_native_roles to true set_fact: manage_native_roles=true when: es_roles is defined and es_roles.native is defined and es_roles.native.keys() | list | length > 0 #If the node has just has security installed it maybe either stopped or started 1. if stopped, we need to start to load native realms 2. if started, we need to restart to load #List current users - name: List Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: user_list_response when: manage_native_users check_mode: no - name: set fact reserved_users equals user_list_response.json set_fact: reserved_users={{ user_list_response.json | filter_reserved }} when: manage_native_users #Current users not inc. those reserved - name: set fact current_users equals user_list_response.json.keys not including reserved set_fact: current_users={{ user_list_response.json.keys() | list | difference (reserved_users) }} when: manage_native_users #We are changing the es_api_basic_auth_username password, so we need to do it first and update the param - name: set fact native_users set_fact: native_users={{ es_users.native }} when: manage_native_users - name: set fact change_api_password to true set_fact: change_api_password=true when: manage_native_users and es_api_basic_auth_username in native_users and native_users[es_api_basic_auth_username].password is defined - name: Update API User Password uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{es_api_basic_auth_username}}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[es_api_basic_auth_username].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: change_api_password - name: set fact es_api_basic_auth_password set_fact: es_api_basic_auth_password={{native_users[es_api_basic_auth_username].password}} when: change_api_password #Identify users that are present in ES but not declared and thus should be removed - name: set fact users_to_remove set_fact: users_to_remove={{ current_users | difference ( native_users.keys() | list) }} when: manage_native_users #Delete all non required users NOT inc. reserved - name: Delete Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{item}}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users and es_delete_unmanaged_native with_items: "{{ users_to_remove | default([]) }}" - name: set fact users_to_ignore set_fact: users_to_ignore={{ native_users.keys() | list | intersect (reserved_users) }} when: manage_native_users - name: debug message debug: msg: "WARNING: YOU CAN ONLY CHANGE THE PASSWORD FOR RESERVED USERS IN THE NATIVE REALM. ANY ROLE CHANGES WILL BE IGNORED: {{users_to_ignore}}" when: manage_native_users and users_to_ignore | length > 0 #Update password on all reserved users - name: Update Reserved User Passwords uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[item].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: native_users[item].password is defined no_log: True with_items: "{{ users_to_ignore | default([]) }}" - name: set fact users_to_modify set_fact: users_to_modify={{ native_users.keys() | list | difference (reserved_users) }} when: manage_native_users #Overwrite all other users NOT inc. those reserved - name: Update Non-Reserved Native User Details uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}" method: POST body_format: json body: "{{ native_users[item] | to_json }}" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users no_log: True with_items: "{{ users_to_modify | default([]) }}" ## ROLE CHANGES #List current roles not. inc those reserved - name: List Native Roles uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: role_list_response when: manage_native_roles check_mode: no - name: set fact reserved roles set_fact: reserved_roles={{ role_list_response.json | filter_reserved }} when: manage_native_roles - name: set fact current roles
set_fact
set_fact: current_roles={{ role_list_response.json.keys() | list | difference (reserved_roles) }} when: manage_native_roles
tasks/xpack/security/elasticsearch-security-native.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - name: set fact change_api_password to false set_fact: change_api_password=false - name: set fact manage_native_users to false set_fact: manage_native_users=false - name: set fact manage_native_users to true set_fact: manage_native_users=true when: es_users is defined and es_users.native is defined and es_users.native.keys() | list | length > 0 - name: set fact manage_native_role to false set_fact: manage_native_roles=false - name: set fact manage_native_roles to true set_fact: manage_native_roles=true when: es_roles is defined and es_roles.native is defined and es_roles.native.keys() | list | length > 0 #If the node has just has security installed it maybe either stopped or started 1. if stopped, we need to start to load native realms 2. if started, we need to restart to load #List current users - name: List Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: user_list_response when: manage_native_users check_mode: no - name: set fact reserved_users equals user_list_response.json set_fact: reserved_users={{ user_list_response.json | filter_reserved }} when: manage_native_users #Current users not inc. those reserved - name: set fact current_users equals user_list_response.json.keys not including reserved set_fact: current_users={{ user_list_response.json.keys() | list | difference (reserved_users) }} when: manage_native_users #We are changing the es_api_basic_auth_username password, so we need to do it first and update the param - name: set fact native_users set_fact: native_users={{ es_users.native }} when: manage_native_users - name: set fact change_api_password to true set_fact: change_api_password=true when: manage_native_users and es_api_basic_auth_username in native_users and native_users[es_api_basic_auth_username].password is defined - name: Update API User Password uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{es_api_basic_auth_username}}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[es_api_basic_auth_username].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: change_api_password - name: set fact es_api_basic_auth_password set_fact: es_api_basic_auth_password={{native_users[es_api_basic_auth_username].password}} when: change_api_password #Identify users that are present in ES but not declared and thus should be removed - name: set fact users_to_remove set_fact: users_to_remove={{ current_users | difference ( native_users.keys() | list) }} when: manage_native_users #Delete all non required users NOT inc. reserved - name: Delete Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{item}}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users and es_delete_unmanaged_native with_items: "{{ users_to_remove | default([]) }}" - name: set fact users_to_ignore set_fact: users_to_ignore={{ native_users.keys() | list | intersect (reserved_users) }} when: manage_native_users - name: debug message debug: msg: "WARNING: YOU CAN ONLY CHANGE THE PASSWORD FOR RESERVED USERS IN THE NATIVE REALM. ANY ROLE CHANGES WILL BE IGNORED: {{users_to_ignore}}" when: manage_native_users and users_to_ignore | length > 0 #Update password on all reserved users - name: Update Reserved User Passwords uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[item].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: native_users[item].password is defined no_log: True with_items: "{{ users_to_ignore | default([]) }}" - name: set fact users_to_modify set_fact: users_to_modify={{ native_users.keys() | list | difference (reserved_users) }} when: manage_native_users #Overwrite all other users NOT inc. those reserved - name: Update Non-Reserved Native User Details uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}" method: POST body_format: json body: "{{ native_users[item] | to_json }}" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users no_log: True with_items: "{{ users_to_modify | default([]) }}" ## ROLE CHANGES #List current roles not. inc those reserved - name: List Native Roles uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: role_list_response when: manage_native_roles check_mode: no - name: set fact reserved roles set_fact: reserved_roles={{ role_list_response.json | filter_reserved }} when: manage_native_roles - name: set fact current roles set_fact: current_roles={{ role_list_response.json.keys() | list | difference (reserved_roles) }} when: manage_native_roles - name: set fact roles to ignore
set_fact
set_fact: roles_to_ignore={{ es_roles.native.keys() | list | intersect (reserved_roles) | default([]) }} when: manage_native_roles
tasks/xpack/security/elasticsearch-security-native.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - name: set fact change_api_password to false set_fact: change_api_password=false - name: set fact manage_native_users to false set_fact: manage_native_users=false - name: set fact manage_native_users to true set_fact: manage_native_users=true when: es_users is defined and es_users.native is defined and es_users.native.keys() | list | length > 0 - name: set fact manage_native_role to false set_fact: manage_native_roles=false - name: set fact manage_native_roles to true set_fact: manage_native_roles=true when: es_roles is defined and es_roles.native is defined and es_roles.native.keys() | list | length > 0 #If the node has just has security installed it maybe either stopped or started 1. if stopped, we need to start to load native realms 2. if started, we need to restart to load #List current users - name: List Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: user_list_response when: manage_native_users check_mode: no - name: set fact reserved_users equals user_list_response.json set_fact: reserved_users={{ user_list_response.json | filter_reserved }} when: manage_native_users #Current users not inc. those reserved - name: set fact current_users equals user_list_response.json.keys not including reserved set_fact: current_users={{ user_list_response.json.keys() | list | difference (reserved_users) }} when: manage_native_users #We are changing the es_api_basic_auth_username password, so we need to do it first and update the param - name: set fact native_users set_fact: native_users={{ es_users.native }} when: manage_native_users - name: set fact change_api_password to true set_fact: change_api_password=true when: manage_native_users and es_api_basic_auth_username in native_users and native_users[es_api_basic_auth_username].password is defined - name: Update API User Password uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{es_api_basic_auth_username}}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[es_api_basic_auth_username].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: change_api_password - name: set fact es_api_basic_auth_password set_fact: es_api_basic_auth_password={{native_users[es_api_basic_auth_username].password}} when: change_api_password #Identify users that are present in ES but not declared and thus should be removed - name: set fact users_to_remove set_fact: users_to_remove={{ current_users | difference ( native_users.keys() | list) }} when: manage_native_users #Delete all non required users NOT inc. reserved - name: Delete Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{item}}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users and es_delete_unmanaged_native with_items: "{{ users_to_remove | default([]) }}" - name: set fact users_to_ignore set_fact: users_to_ignore={{ native_users.keys() | list | intersect (reserved_users) }} when: manage_native_users - name: debug message debug: msg: "WARNING: YOU CAN ONLY CHANGE THE PASSWORD FOR RESERVED USERS IN THE NATIVE REALM. ANY ROLE CHANGES WILL BE IGNORED: {{users_to_ignore}}" when: manage_native_users and users_to_ignore | length > 0 #Update password on all reserved users - name: Update Reserved User Passwords uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[item].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: native_users[item].password is defined no_log: True with_items: "{{ users_to_ignore | default([]) }}" - name: set fact users_to_modify set_fact: users_to_modify={{ native_users.keys() | list | difference (reserved_users) }} when: manage_native_users #Overwrite all other users NOT inc. those reserved - name: Update Non-Reserved Native User Details uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}" method: POST body_format: json body: "{{ native_users[item] | to_json }}" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users no_log: True with_items: "{{ users_to_modify | default([]) }}" ## ROLE CHANGES #List current roles not. inc those reserved - name: List Native Roles uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: role_list_response when: manage_native_roles check_mode: no - name: set fact reserved roles set_fact: reserved_roles={{ role_list_response.json | filter_reserved }} when: manage_native_roles - name: set fact current roles set_fact: current_roles={{ role_list_response.json.keys() | list | difference (reserved_roles) }} when: manage_native_roles - name: set fact roles to ignore set_fact: roles_to_ignore={{ es_roles.native.keys() | list | intersect (reserved_roles) | default([]) }} when: manage_native_roles - name: debug message
debug
debug: msg: "WARNING: YOU CANNOT CHANGE RESERVED ROLES. THE FOLLOWING WILL BE IGNORED: {{roles_to_ignore}}" when: manage_native_roles and roles_to_ignore | length > 0
tasks/xpack/security/elasticsearch-security-native.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - name: set fact change_api_password to false set_fact: change_api_password=false - name: set fact manage_native_users to false set_fact: manage_native_users=false - name: set fact manage_native_users to true set_fact: manage_native_users=true when: es_users is defined and es_users.native is defined and es_users.native.keys() | list | length > 0 - name: set fact manage_native_role to false set_fact: manage_native_roles=false - name: set fact manage_native_roles to true set_fact: manage_native_roles=true when: es_roles is defined and es_roles.native is defined and es_roles.native.keys() | list | length > 0 #If the node has just has security installed it maybe either stopped or started 1. if stopped, we need to start to load native realms 2. if started, we need to restart to load #List current users - name: List Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: user_list_response when: manage_native_users check_mode: no - name: set fact reserved_users equals user_list_response.json set_fact: reserved_users={{ user_list_response.json | filter_reserved }} when: manage_native_users #Current users not inc. those reserved - name: set fact current_users equals user_list_response.json.keys not including reserved set_fact: current_users={{ user_list_response.json.keys() | list | difference (reserved_users) }} when: manage_native_users #We are changing the es_api_basic_auth_username password, so we need to do it first and update the param - name: set fact native_users set_fact: native_users={{ es_users.native }} when: manage_native_users - name: set fact change_api_password to true set_fact: change_api_password=true when: manage_native_users and es_api_basic_auth_username in native_users and native_users[es_api_basic_auth_username].password is defined - name: Update API User Password uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{es_api_basic_auth_username}}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[es_api_basic_auth_username].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: change_api_password - name: set fact es_api_basic_auth_password set_fact: es_api_basic_auth_password={{native_users[es_api_basic_auth_username].password}} when: change_api_password #Identify users that are present in ES but not declared and thus should be removed - name: set fact users_to_remove set_fact: users_to_remove={{ current_users | difference ( native_users.keys() | list) }} when: manage_native_users #Delete all non required users NOT inc. reserved - name: Delete Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{item}}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users and es_delete_unmanaged_native with_items: "{{ users_to_remove | default([]) }}" - name: set fact users_to_ignore set_fact: users_to_ignore={{ native_users.keys() | list | intersect (reserved_users) }} when: manage_native_users - name: debug message debug: msg: "WARNING: YOU CAN ONLY CHANGE THE PASSWORD FOR RESERVED USERS IN THE NATIVE REALM. ANY ROLE CHANGES WILL BE IGNORED: {{users_to_ignore}}" when: manage_native_users and users_to_ignore | length > 0 #Update password on all reserved users - name: Update Reserved User Passwords uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[item].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: native_users[item].password is defined no_log: True with_items: "{{ users_to_ignore | default([]) }}" - name: set fact users_to_modify set_fact: users_to_modify={{ native_users.keys() | list | difference (reserved_users) }} when: manage_native_users #Overwrite all other users NOT inc. those reserved - name: Update Non-Reserved Native User Details uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}" method: POST body_format: json body: "{{ native_users[item] | to_json }}" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users no_log: True with_items: "{{ users_to_modify | default([]) }}" ## ROLE CHANGES #List current roles not. inc those reserved - name: List Native Roles uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: role_list_response when: manage_native_roles check_mode: no - name: set fact reserved roles set_fact: reserved_roles={{ role_list_response.json | filter_reserved }} when: manage_native_roles - name: set fact current roles set_fact: current_roles={{ role_list_response.json.keys() | list | difference (reserved_roles) }} when: manage_native_roles - name: set fact roles to ignore set_fact: roles_to_ignore={{ es_roles.native.keys() | list | intersect (reserved_roles) | default([]) }} when: manage_native_roles - name: debug message debug: msg: "WARNING: YOU CANNOT CHANGE RESERVED ROLES. THE FOLLOWING WILL BE IGNORED: {{roles_to_ignore}}" when: manage_native_roles and roles_to_ignore | length > 0 - name: set fact roles_to_remove
set_fact
set_fact: roles_to_remove={{ current_roles | difference ( es_roles.native.keys() | list) }} when: manage_native_roles #Delete all non required roles NOT inc. reserved
tasks/xpack/security/elasticsearch-security-native.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - name: set fact change_api_password to false set_fact: change_api_password=false - name: set fact manage_native_users to false set_fact: manage_native_users=false - name: set fact manage_native_users to true set_fact: manage_native_users=true when: es_users is defined and es_users.native is defined and es_users.native.keys() | list | length > 0 - name: set fact manage_native_role to false set_fact: manage_native_roles=false - name: set fact manage_native_roles to true set_fact: manage_native_roles=true when: es_roles is defined and es_roles.native is defined and es_roles.native.keys() | list | length > 0 #If the node has just has security installed it maybe either stopped or started 1. if stopped, we need to start to load native realms 2. if started, we need to restart to load #List current users - name: List Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: user_list_response when: manage_native_users check_mode: no - name: set fact reserved_users equals user_list_response.json set_fact: reserved_users={{ user_list_response.json | filter_reserved }} when: manage_native_users #Current users not inc. those reserved - name: set fact current_users equals user_list_response.json.keys not including reserved set_fact: current_users={{ user_list_response.json.keys() | list | difference (reserved_users) }} when: manage_native_users #We are changing the es_api_basic_auth_username password, so we need to do it first and update the param - name: set fact native_users set_fact: native_users={{ es_users.native }} when: manage_native_users - name: set fact change_api_password to true set_fact: change_api_password=true when: manage_native_users and es_api_basic_auth_username in native_users and native_users[es_api_basic_auth_username].password is defined - name: Update API User Password uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{es_api_basic_auth_username}}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[es_api_basic_auth_username].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: change_api_password - name: set fact es_api_basic_auth_password set_fact: es_api_basic_auth_password={{native_users[es_api_basic_auth_username].password}} when: change_api_password #Identify users that are present in ES but not declared and thus should be removed - name: set fact users_to_remove set_fact: users_to_remove={{ current_users | difference ( native_users.keys() | list) }} when: manage_native_users #Delete all non required users NOT inc. reserved - name: Delete Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{item}}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users and es_delete_unmanaged_native with_items: "{{ users_to_remove | default([]) }}" - name: set fact users_to_ignore set_fact: users_to_ignore={{ native_users.keys() | list | intersect (reserved_users) }} when: manage_native_users - name: debug message debug: msg: "WARNING: YOU CAN ONLY CHANGE THE PASSWORD FOR RESERVED USERS IN THE NATIVE REALM. ANY ROLE CHANGES WILL BE IGNORED: {{users_to_ignore}}" when: manage_native_users and users_to_ignore | length > 0 #Update password on all reserved users - name: Update Reserved User Passwords uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[item].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: native_users[item].password is defined no_log: True with_items: "{{ users_to_ignore | default([]) }}" - name: set fact users_to_modify set_fact: users_to_modify={{ native_users.keys() | list | difference (reserved_users) }} when: manage_native_users #Overwrite all other users NOT inc. those reserved - name: Update Non-Reserved Native User Details uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}" method: POST body_format: json body: "{{ native_users[item] | to_json }}" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users no_log: True with_items: "{{ users_to_modify | default([]) }}" ## ROLE CHANGES #List current roles not. inc those reserved - name: List Native Roles uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: role_list_response when: manage_native_roles check_mode: no - name: set fact reserved roles set_fact: reserved_roles={{ role_list_response.json | filter_reserved }} when: manage_native_roles - name: set fact current roles set_fact: current_roles={{ role_list_response.json.keys() | list | difference (reserved_roles) }} when: manage_native_roles - name: set fact roles to ignore set_fact: roles_to_ignore={{ es_roles.native.keys() | list | intersect (reserved_roles) | default([]) }} when: manage_native_roles - name: debug message debug: msg: "WARNING: YOU CANNOT CHANGE RESERVED ROLES. THE FOLLOWING WILL BE IGNORED: {{roles_to_ignore}}" when: manage_native_roles and roles_to_ignore | length > 0 - name: set fact roles_to_remove set_fact: roles_to_remove={{ current_roles | difference ( es_roles.native.keys() | list) }} when: manage_native_roles #Delete all non required roles NOT inc. reserved - name: Delete Native Roles
uri
uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role/{{ item | urlencode }}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_roles and es_delete_unmanaged_native with_items: "{{roles_to_remove | default([]) }}"
tasks/xpack/security/elasticsearch-security-native.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - name: set fact change_api_password to false set_fact: change_api_password=false - name: set fact manage_native_users to false set_fact: manage_native_users=false - name: set fact manage_native_users to true set_fact: manage_native_users=true when: es_users is defined and es_users.native is defined and es_users.native.keys() | list | length > 0 - name: set fact manage_native_role to false set_fact: manage_native_roles=false - name: set fact manage_native_roles to true set_fact: manage_native_roles=true when: es_roles is defined and es_roles.native is defined and es_roles.native.keys() | list | length > 0 #If the node has just has security installed it maybe either stopped or started 1. if stopped, we need to start to load native realms 2. if started, we need to restart to load #List current users - name: List Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: user_list_response when: manage_native_users check_mode: no - name: set fact reserved_users equals user_list_response.json set_fact: reserved_users={{ user_list_response.json | filter_reserved }} when: manage_native_users #Current users not inc. those reserved - name: set fact current_users equals user_list_response.json.keys not including reserved set_fact: current_users={{ user_list_response.json.keys() | list | difference (reserved_users) }} when: manage_native_users #We are changing the es_api_basic_auth_username password, so we need to do it first and update the param - name: set fact native_users set_fact: native_users={{ es_users.native }} when: manage_native_users - name: set fact change_api_password to true set_fact: change_api_password=true when: manage_native_users and es_api_basic_auth_username in native_users and native_users[es_api_basic_auth_username].password is defined - name: Update API User Password uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{es_api_basic_auth_username}}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[es_api_basic_auth_username].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: change_api_password - name: set fact es_api_basic_auth_password set_fact: es_api_basic_auth_password={{native_users[es_api_basic_auth_username].password}} when: change_api_password #Identify users that are present in ES but not declared and thus should be removed - name: set fact users_to_remove set_fact: users_to_remove={{ current_users | difference ( native_users.keys() | list) }} when: manage_native_users #Delete all non required users NOT inc. reserved - name: Delete Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{item}}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users and es_delete_unmanaged_native with_items: "{{ users_to_remove | default([]) }}" - name: set fact users_to_ignore set_fact: users_to_ignore={{ native_users.keys() | list | intersect (reserved_users) }} when: manage_native_users - name: debug message debug: msg: "WARNING: YOU CAN ONLY CHANGE THE PASSWORD FOR RESERVED USERS IN THE NATIVE REALM. ANY ROLE CHANGES WILL BE IGNORED: {{users_to_ignore}}" when: manage_native_users and users_to_ignore | length > 0 #Update password on all reserved users - name: Update Reserved User Passwords uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[item].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: native_users[item].password is defined no_log: True with_items: "{{ users_to_ignore | default([]) }}" - name: set fact users_to_modify set_fact: users_to_modify={{ native_users.keys() | list | difference (reserved_users) }} when: manage_native_users #Overwrite all other users NOT inc. those reserved - name: Update Non-Reserved Native User Details uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}" method: POST body_format: json body: "{{ native_users[item] | to_json }}" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users no_log: True with_items: "{{ users_to_modify | default([]) }}" ## ROLE CHANGES #List current roles not. inc those reserved - name: List Native Roles uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: role_list_response when: manage_native_roles check_mode: no - name: set fact reserved roles set_fact: reserved_roles={{ role_list_response.json | filter_reserved }} when: manage_native_roles - name: set fact current roles set_fact: current_roles={{ role_list_response.json.keys() | list | difference (reserved_roles) }} when: manage_native_roles - name: set fact roles to ignore set_fact: roles_to_ignore={{ es_roles.native.keys() | list | intersect (reserved_roles) | default([]) }} when: manage_native_roles - name: debug message debug: msg: "WARNING: YOU CANNOT CHANGE RESERVED ROLES. THE FOLLOWING WILL BE IGNORED: {{roles_to_ignore}}" when: manage_native_roles and roles_to_ignore | length > 0 - name: set fact roles_to_remove set_fact: roles_to_remove={{ current_roles | difference ( es_roles.native.keys() | list) }} when: manage_native_roles #Delete all non required roles NOT inc. reserved - name: Delete Native Roles uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role/{{ item | urlencode }}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_roles and es_delete_unmanaged_native with_items: "{{roles_to_remove | default([]) }}" - name: set fact roles_to_modify
set_fact
set_fact: roles_to_modify={{ es_roles.native.keys() | list | difference (reserved_roles) }} when: manage_native_roles #Update other roles - NOT inc. reserved roles
tasks/xpack/security/elasticsearch-security-native.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - name: set fact change_api_password to false set_fact: change_api_password=false - name: set fact manage_native_users to false set_fact: manage_native_users=false - name: set fact manage_native_users to true set_fact: manage_native_users=true when: es_users is defined and es_users.native is defined and es_users.native.keys() | list | length > 0 - name: set fact manage_native_role to false set_fact: manage_native_roles=false - name: set fact manage_native_roles to true set_fact: manage_native_roles=true when: es_roles is defined and es_roles.native is defined and es_roles.native.keys() | list | length > 0 #If the node has just has security installed it maybe either stopped or started 1. if stopped, we need to start to load native realms 2. if started, we need to restart to load #List current users - name: List Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: user_list_response when: manage_native_users check_mode: no - name: set fact reserved_users equals user_list_response.json set_fact: reserved_users={{ user_list_response.json | filter_reserved }} when: manage_native_users #Current users not inc. those reserved - name: set fact current_users equals user_list_response.json.keys not including reserved set_fact: current_users={{ user_list_response.json.keys() | list | difference (reserved_users) }} when: manage_native_users #We are changing the es_api_basic_auth_username password, so we need to do it first and update the param - name: set fact native_users set_fact: native_users={{ es_users.native }} when: manage_native_users - name: set fact change_api_password to true set_fact: change_api_password=true when: manage_native_users and es_api_basic_auth_username in native_users and native_users[es_api_basic_auth_username].password is defined - name: Update API User Password uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{es_api_basic_auth_username}}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[es_api_basic_auth_username].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: change_api_password - name: set fact es_api_basic_auth_password set_fact: es_api_basic_auth_password={{native_users[es_api_basic_auth_username].password}} when: change_api_password #Identify users that are present in ES but not declared and thus should be removed - name: set fact users_to_remove set_fact: users_to_remove={{ current_users | difference ( native_users.keys() | list) }} when: manage_native_users #Delete all non required users NOT inc. reserved - name: Delete Native Users uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{item}}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users and es_delete_unmanaged_native with_items: "{{ users_to_remove | default([]) }}" - name: set fact users_to_ignore set_fact: users_to_ignore={{ native_users.keys() | list | intersect (reserved_users) }} when: manage_native_users - name: debug message debug: msg: "WARNING: YOU CAN ONLY CHANGE THE PASSWORD FOR RESERVED USERS IN THE NATIVE REALM. ANY ROLE CHANGES WILL BE IGNORED: {{users_to_ignore}}" when: manage_native_users and users_to_ignore | length > 0 #Update password on all reserved users - name: Update Reserved User Passwords uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}/_password" method: POST body_format: json body: "{ \"password\":\"{{native_users[item].password}}\" }" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: native_users[item].password is defined no_log: True with_items: "{{ users_to_ignore | default([]) }}" - name: set fact users_to_modify set_fact: users_to_modify={{ native_users.keys() | list | difference (reserved_users) }} when: manage_native_users #Overwrite all other users NOT inc. those reserved - name: Update Non-Reserved Native User Details uri: url: "{{ es_api_uri }}/{{ es_security_api }}/user/{{ item | urlencode }}" method: POST body_format: json body: "{{ native_users[item] | to_json }}" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_users no_log: True with_items: "{{ users_to_modify | default([]) }}" ## ROLE CHANGES #List current roles not. inc those reserved - name: List Native Roles uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role" method: GET user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes status_code: 200 validate_certs: "{{ es_validate_certs }}" register: role_list_response when: manage_native_roles check_mode: no - name: set fact reserved roles set_fact: reserved_roles={{ role_list_response.json | filter_reserved }} when: manage_native_roles - name: set fact current roles set_fact: current_roles={{ role_list_response.json.keys() | list | difference (reserved_roles) }} when: manage_native_roles - name: set fact roles to ignore set_fact: roles_to_ignore={{ es_roles.native.keys() | list | intersect (reserved_roles) | default([]) }} when: manage_native_roles - name: debug message debug: msg: "WARNING: YOU CANNOT CHANGE RESERVED ROLES. THE FOLLOWING WILL BE IGNORED: {{roles_to_ignore}}" when: manage_native_roles and roles_to_ignore | length > 0 - name: set fact roles_to_remove set_fact: roles_to_remove={{ current_roles | difference ( es_roles.native.keys() | list) }} when: manage_native_roles #Delete all non required roles NOT inc. reserved - name: Delete Native Roles uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role/{{ item | urlencode }}" method: DELETE status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_roles and es_delete_unmanaged_native with_items: "{{roles_to_remove | default([]) }}" - name: set fact roles_to_modify set_fact: roles_to_modify={{ es_roles.native.keys() | list | difference (reserved_roles) }} when: manage_native_roles #Update other roles - NOT inc. reserved roles - name: Update Native Roles
uri
uri: url: "{{ es_api_uri }}/{{ es_security_api }}/role/{{ item | urlencode }}" method: POST body_format: json body: "{{ es_roles.native[item] | to_json}}" status_code: 200 user: "{{es_api_basic_auth_username}}" password: "{{es_api_basic_auth_password}}" force_basic_auth: yes validate_certs: "{{ es_validate_certs }}" when: manage_native_roles with_items: "{{ roles_to_modify | default([]) }}"
tasks/xpack/security/elasticsearch-security-native.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists
stat
become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location
copy
become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users - name: List Users
shell
become: yes shell: cat {{ es_conf_dir }}/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users changed_when: False check_mode: no
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users - name: List Users become: yes shell: cat {{ es_conf_dir }}/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users changed_when: False check_mode: no - name: set fact users_to_remove
set_fact
set_fact: users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys() | list) }} when: manage_file_users and es_delete_unmanaged_file #Remove users
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users - name: List Users become: yes shell: cat {{ es_conf_dir }}/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users changed_when: False check_mode: no - name: set fact users_to_remove set_fact: users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys() | list) }} when: manage_file_users and es_delete_unmanaged_file #Remove users - name: Remove Users
command
become: yes command: > {{es_home}}/bin/elasticsearch-users userdel {{item}} with_items: "{{users_to_remove | default([])}}" when: manage_file_users environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}"
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users - name: List Users become: yes shell: cat {{ es_conf_dir }}/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users changed_when: False check_mode: no - name: set fact users_to_remove set_fact: users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys() | list) }} when: manage_file_users and es_delete_unmanaged_file #Remove users - name: Remove Users become: yes command: > {{es_home}}/bin/elasticsearch-users userdel {{item}} with_items: "{{users_to_remove | default([])}}" when: manage_file_users environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" - name: set fact users_to_add
set_fact
set_fact: users_to_add={{ es_users.file.keys() | list | difference (current_file_users.stdout_lines) }} when: manage_file_users and es_delete_unmanaged_file #Add users
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users - name: List Users become: yes shell: cat {{ es_conf_dir }}/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users changed_when: False check_mode: no - name: set fact users_to_remove set_fact: users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys() | list) }} when: manage_file_users and es_delete_unmanaged_file #Remove users - name: Remove Users become: yes command: > {{es_home}}/bin/elasticsearch-users userdel {{item}} with_items: "{{users_to_remove | default([])}}" when: manage_file_users environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" - name: set fact users_to_add set_fact: users_to_add={{ es_users.file.keys() | list | difference (current_file_users.stdout_lines) }} when: manage_file_users and es_delete_unmanaged_file #Add users - name: Add Users
command
become: yes command: > {{es_home}}/bin/elasticsearch-users useradd {{item}} -p {{es_users.file[item].password}} with_items: "{{ users_to_add | default([]) }}" when: manage_file_users no_log: True environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" #Set passwords for all users declared - Required as the useradd will not change existing user passwords
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users - name: List Users become: yes shell: cat {{ es_conf_dir }}/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users changed_when: False check_mode: no - name: set fact users_to_remove set_fact: users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys() | list) }} when: manage_file_users and es_delete_unmanaged_file #Remove users - name: Remove Users become: yes command: > {{es_home}}/bin/elasticsearch-users userdel {{item}} with_items: "{{users_to_remove | default([])}}" when: manage_file_users environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" - name: set fact users_to_add set_fact: users_to_add={{ es_users.file.keys() | list | difference (current_file_users.stdout_lines) }} when: manage_file_users and es_delete_unmanaged_file #Add users - name: Add Users become: yes command: > {{es_home}}/bin/elasticsearch-users useradd {{item}} -p {{es_users.file[item].password}} with_items: "{{ users_to_add | default([]) }}" when: manage_file_users no_log: True environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" #Set passwords for all users declared - Required as the useradd will not change existing user passwords - name: Set User Passwords
command
become: yes command: > {{es_home}}/bin/elasticsearch-users passwd {{ item }} -p {{es_users.file[item].password}} with_items: "{{ es_users.file.keys() | list }}" when: manage_file_users #Currently no easy way to figure out if the password has changed or to know what it currently is so we can skip. changed_when: False no_log: True environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}"
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users - name: List Users become: yes shell: cat {{ es_conf_dir }}/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users changed_when: False check_mode: no - name: set fact users_to_remove set_fact: users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys() | list) }} when: manage_file_users and es_delete_unmanaged_file #Remove users - name: Remove Users become: yes command: > {{es_home}}/bin/elasticsearch-users userdel {{item}} with_items: "{{users_to_remove | default([])}}" when: manage_file_users environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" - name: set fact users_to_add set_fact: users_to_add={{ es_users.file.keys() | list | difference (current_file_users.stdout_lines) }} when: manage_file_users and es_delete_unmanaged_file #Add users - name: Add Users become: yes command: > {{es_home}}/bin/elasticsearch-users useradd {{item}} -p {{es_users.file[item].password}} with_items: "{{ users_to_add | default([]) }}" when: manage_file_users no_log: True environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" #Set passwords for all users declared - Required as the useradd will not change existing user passwords - name: Set User Passwords become: yes command: > {{es_home}}/bin/elasticsearch-users passwd {{ item }} -p {{es_users.file[item].password}} with_items: "{{ es_users.file.keys() | list }}" when: manage_file_users #Currently no easy way to figure out if the password has changed or to know what it currently is so we can skip. changed_when: False no_log: True environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" - name: set fact users_roles
set_fact
set_fact: users_roles={{es_users.file | extract_role_users () }} when: manage_file_users #Copy Roles files
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users - name: List Users become: yes shell: cat {{ es_conf_dir }}/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users changed_when: False check_mode: no - name: set fact users_to_remove set_fact: users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys() | list) }} when: manage_file_users and es_delete_unmanaged_file #Remove users - name: Remove Users become: yes command: > {{es_home}}/bin/elasticsearch-users userdel {{item}} with_items: "{{users_to_remove | default([])}}" when: manage_file_users environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" - name: set fact users_to_add set_fact: users_to_add={{ es_users.file.keys() | list | difference (current_file_users.stdout_lines) }} when: manage_file_users and es_delete_unmanaged_file #Add users - name: Add Users become: yes command: > {{es_home}}/bin/elasticsearch-users useradd {{item}} -p {{es_users.file[item].password}} with_items: "{{ users_to_add | default([]) }}" when: manage_file_users no_log: True environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" #Set passwords for all users declared - Required as the useradd will not change existing user passwords - name: Set User Passwords become: yes command: > {{es_home}}/bin/elasticsearch-users passwd {{ item }} -p {{es_users.file[item].password}} with_items: "{{ es_users.file.keys() | list }}" when: manage_file_users #Currently no easy way to figure out if the password has changed or to know what it currently is so we can skip. changed_when: False no_log: True environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" - name: set fact users_roles set_fact: users_roles={{es_users.file | extract_role_users () }} when: manage_file_users #Copy Roles files - name: Copy roles.yml File for Instance
template
become: yes template: src: security/roles.yml.j2 dest: "{{ es_conf_dir }}/roles.yml" owner: root group: "{{ es_group }}" mode: "0660" force: yes when: es_roles is defined and es_roles.file is defined #Overwrite users_roles file
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - set_fact: manage_file_users=false - set_fact: manage_file_users=true when: es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0 # Users migration from elasticsearch < 6.3 versions - name: Check if old users file exists become: yes stat: path: '{{ es_conf_dir }}/x-pack/users' register: old_users_file check_mode: no - name: Copy the old users file from the old deprecated location become: yes copy: remote_src: yes force: no # only copy it if the new path doesn't exist yet src: "{{ es_conf_dir }}/x-pack/users" dest: "{{ es_conf_dir }}/users" group: "{{ es_group }}" owner: root when: old_users_file.stat.exists # End of users migrations #List current users - name: List Users become: yes shell: cat {{ es_conf_dir }}/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users changed_when: False check_mode: no - name: set fact users_to_remove set_fact: users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys() | list) }} when: manage_file_users and es_delete_unmanaged_file #Remove users - name: Remove Users become: yes command: > {{es_home}}/bin/elasticsearch-users userdel {{item}} with_items: "{{users_to_remove | default([])}}" when: manage_file_users environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" - name: set fact users_to_add set_fact: users_to_add={{ es_users.file.keys() | list | difference (current_file_users.stdout_lines) }} when: manage_file_users and es_delete_unmanaged_file #Add users - name: Add Users become: yes command: > {{es_home}}/bin/elasticsearch-users useradd {{item}} -p {{es_users.file[item].password}} with_items: "{{ users_to_add | default([]) }}" when: manage_file_users no_log: True environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" #Set passwords for all users declared - Required as the useradd will not change existing user passwords - name: Set User Passwords become: yes command: > {{es_home}}/bin/elasticsearch-users passwd {{ item }} -p {{es_users.file[item].password}} with_items: "{{ es_users.file.keys() | list }}" when: manage_file_users #Currently no easy way to figure out if the password has changed or to know what it currently is so we can skip. changed_when: False no_log: True environment: CONF_DIR: "{{ es_conf_dir }}" ES_PATH_CONF: "{{ es_conf_dir }}" ES_HOME: "{{es_home}}" - name: set fact users_roles set_fact: users_roles={{es_users.file | extract_role_users () }} when: manage_file_users #Copy Roles files - name: Copy roles.yml File for Instance become: yes template: src: security/roles.yml.j2 dest: "{{ es_conf_dir }}/roles.yml" owner: root group: "{{ es_group }}" mode: "0660" force: yes when: es_roles is defined and es_roles.file is defined #Overwrite users_roles file - name: Copy User Roles
template
become: yes template: src: security/users_roles.j2 dest: "{{ es_conf_dir }}/users_roles" owner: root group: "{{ es_group }}" mode: "0660" force: yes when: manage_file_users and users_roles | length > 0
tasks/xpack/security/elasticsearch-security-file.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
- name: reload systemd configuration
systemd
become: yes systemd: daemon_reload: true # Restart service and ensure it is enabled
handlers/main.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
- name: reload systemd configuration become: yes systemd: daemon_reload: true # Restart service and ensure it is enabled - name: restart elasticsearch
service
become: yes service: name=elasticsearch state=restarted enabled=yes when: - es_restart_on_change - es_start_service register: es_restarted
handlers/main.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
--- - name: Dump all variables to a file
copy
changed_when: False copy: content: '{{ vars | to_nice_json }} ' dest: '/tmp/vars.json'
test/integration/debug.yml
ansible-elasticsearch
https://github.com/elastic/ansible-elasticsearch
################################################## # DO Community Playbooks: Apache on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites
apt
apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ]
apache_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: Apache on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install Apache
apt
apt: name=apache2 update_cache=yes state=latest
apache_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: Apache on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install Apache apt: name=apache2 update_cache=yes state=latest - name: Create document root
file
file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755'
apache_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: Apache on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install Apache apt: name=apache2 update_cache=yes state=latest - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Copy index test page
template
template: src: "files/index.html.j2" dest: "/var/www/{{ http_host }}/index.html"
apache_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: Apache on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install Apache apt: name=apache2 update_cache=yes state=latest - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Copy index test page template: src: "files/index.html.j2" dest: "/var/www/{{ http_host }}/index.html" - name: Set up Apache virtualhost
template
template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}"
apache_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: Apache on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install Apache apt: name=apache2 update_cache=yes state=latest - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Copy index test page template: src: "files/index.html.j2" dest: "/var/www/{{ http_host }}/index.html" - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" - name: Enable new site
shell
shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache
apache_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: Apache on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install Apache apt: name=apache2 update_cache=yes state=latest - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Copy index test page template: src: "files/index.html.j2" dest: "/var/www/{{ http_host }}/index.html" - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache - name: Disable default Apache site
shell
shell: /usr/sbin/a2dissite 000-default.conf when: disable_default notify: Reload Apache
apache_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: Apache on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install Apache apt: name=apache2 update_cache=yes state=latest - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Copy index test page template: src: "files/index.html.j2" dest: "/var/www/{{ http_host }}/index.html" - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf when: disable_default notify: Reload Apache - name: "UFW - Allow HTTP on port {{ http_port }}"
ufw
" ufw: rule: allow port: "{{ http_port }}" proto: tcp handlers:
apache_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Docker ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install aptitude using apt
apt
apt: name=aptitude state=latest update_cache=yes force_apt_get=yes
docker_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Docker ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install aptitude using apt apt: name=aptitude state=latest update_cache=yes force_apt_get=yes - name: Install required system packages
apt
apt: name={{ item }} state=latest update_cache=yes loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools']
docker_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Docker ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install aptitude using apt apt: name=aptitude state=latest update_cache=yes force_apt_get=yes - name: Install required system packages apt: name={{ item }} state=latest update_cache=yes loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools'] - name: Add Docker GPG apt Key
apt_key
apt_key: url: https://download.docker.com/linux/ubuntu/gpg state: present
docker_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Docker ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install aptitude using apt apt: name=aptitude state=latest update_cache=yes force_apt_get=yes - name: Install required system packages apt: name={{ item }} state=latest update_cache=yes loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools'] - name: Add Docker GPG apt Key apt_key: url: https://download.docker.com/linux/ubuntu/gpg state: present - name: Add Docker Repository
apt_repository
apt_repository: repo: deb https://download.docker.com/linux/ubuntu bionic stable state: present
docker_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Docker ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install aptitude using apt apt: name=aptitude state=latest update_cache=yes force_apt_get=yes - name: Install required system packages apt: name={{ item }} state=latest update_cache=yes loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools'] - name: Add Docker GPG apt Key apt_key: url: https://download.docker.com/linux/ubuntu/gpg state: present - name: Add Docker Repository apt_repository: repo: deb https://download.docker.com/linux/ubuntu bionic stable state: present - name: Update apt and install docker-ce
apt
apt: update_cache=yes name=docker-ce state=latest
docker_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Docker ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install aptitude using apt apt: name=aptitude state=latest update_cache=yes force_apt_get=yes - name: Install required system packages apt: name={{ item }} state=latest update_cache=yes loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools'] - name: Add Docker GPG apt Key apt_key: url: https://download.docker.com/linux/ubuntu/gpg state: present - name: Add Docker Repository apt_repository: repo: deb https://download.docker.com/linux/ubuntu bionic stable state: present - name: Update apt and install docker-ce apt: update_cache=yes name=docker-ce state=latest - name: Install Docker Module for Python
pip
pip: name: docker
docker_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Docker ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install aptitude using apt apt: name=aptitude state=latest update_cache=yes force_apt_get=yes - name: Install required system packages apt: name={{ item }} state=latest update_cache=yes loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools'] - name: Add Docker GPG apt Key apt_key: url: https://download.docker.com/linux/ubuntu/gpg state: present - name: Add Docker Repository apt_repository: repo: deb https://download.docker.com/linux/ubuntu bionic stable state: present - name: Update apt and install docker-ce apt: update_cache=yes name=docker-ce state=latest - name: Install Docker Module for Python pip: name: docker - name: Pull default Docker image
docker_image
docker_image: name: "{{ default_container_image }}" source: pull # Creates the number of containers defined by the variable create_containers, using values from vars file
docker_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Docker ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install aptitude using apt apt: name=aptitude state=latest update_cache=yes force_apt_get=yes - name: Install required system packages apt: name={{ item }} state=latest update_cache=yes loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools'] - name: Add Docker GPG apt Key apt_key: url: https://download.docker.com/linux/ubuntu/gpg state: present - name: Add Docker Repository apt_repository: repo: deb https://download.docker.com/linux/ubuntu bionic stable state: present - name: Update apt and install docker-ce apt: update_cache=yes name=docker-ce state=latest - name: Install Docker Module for Python pip: name: docker - name: Pull default Docker image docker_image: name: "{{ default_container_image }}" source: pull # Creates the number of containers defined by the variable create_containers, using values from vars file - name: Create default containers
docker_container
docker_container: name: "{{ default_container_name }}{{ item }}" image: "{{ default_container_image }}" command: "{{ default_container_command }}" state: present with_sequence: count={{ create_containers }}
docker_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites
apt
apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages
apt
apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions
apt
apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root
file
file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost
template
template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module
shell
shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site
shell
shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site
shell
shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password
mysql_user
mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts
mysql_user
mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Remove the MySQL test database
mysql_db
mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Remove the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Creates database for WordPress
mysql_db
mysql_db: name: "{{ mysql_db }}" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Remove the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Creates database for WordPress mysql_db: name: "{{ mysql_db }}" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Create MySQL user for WordPress
mysql_user
mysql_user: name: "{{ mysql_user }}" password: "{{ mysql_password }}" priv: "{{ mysql_db }}.*:ALL" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] # UFW Configuration
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Remove the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Creates database for WordPress mysql_db: name: "{{ mysql_db }}" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Create MySQL user for WordPress mysql_user: name: "{{ mysql_user }}" password: "{{ mysql_password }}" priv: "{{ mysql_db }}.*:ALL" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}"
ufw
" ufw: rule: allow port: "{{ http_port }}" proto: tcp tags: [ system ] # WordPress Configuration
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Remove the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Creates database for WordPress mysql_db: name: "{{ mysql_db }}" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Create MySQL user for WordPress mysql_user: name: "{{ mysql_user }}" password: "{{ mysql_password }}" priv: "{{ mysql_db }}.*:ALL" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}" ufw: rule: allow port: "{{ http_port }}" proto: tcp tags: [ system ] # WordPress Configuration - name: Download and unpack latest WordPress
unarchive
unarchive: src: https://wordpress.org/latest.tar.gz dest: "/var/www/{{ http_host }}" remote_src: yes creates: "/var/www/{{ http_host }}/wordpress" tags: [ wordpress ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Remove the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Creates database for WordPress mysql_db: name: "{{ mysql_db }}" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Create MySQL user for WordPress mysql_user: name: "{{ mysql_user }}" password: "{{ mysql_password }}" priv: "{{ mysql_db }}.*:ALL" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}" ufw: rule: allow port: "{{ http_port }}" proto: tcp tags: [ system ] # WordPress Configuration - name: Download and unpack latest WordPress unarchive: src: https://wordpress.org/latest.tar.gz dest: "/var/www/{{ http_host }}" remote_src: yes creates: "/var/www/{{ http_host }}/wordpress" tags: [ wordpress ] - name: Set ownership
file
file: path: "/var/www/{{ http_host }}" state: directory recurse: yes owner: www-data group: www-data tags: [ wordpress ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Remove the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Creates database for WordPress mysql_db: name: "{{ mysql_db }}" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Create MySQL user for WordPress mysql_user: name: "{{ mysql_user }}" password: "{{ mysql_password }}" priv: "{{ mysql_db }}.*:ALL" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}" ufw: rule: allow port: "{{ http_port }}" proto: tcp tags: [ system ] # WordPress Configuration - name: Download and unpack latest WordPress unarchive: src: https://wordpress.org/latest.tar.gz dest: "/var/www/{{ http_host }}" remote_src: yes creates: "/var/www/{{ http_host }}/wordpress" tags: [ wordpress ] - name: Set ownership file: path: "/var/www/{{ http_host }}" state: directory recurse: yes owner: www-data group: www-data tags: [ wordpress ] - name: Set permissions for directories
shell
shell: "/usr/bin/find /var/www/{{ http_host }}/wordpress/ -type d -exec chmod 750 {} \\;" tags: [ wordpress ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Remove the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Creates database for WordPress mysql_db: name: "{{ mysql_db }}" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Create MySQL user for WordPress mysql_user: name: "{{ mysql_user }}" password: "{{ mysql_password }}" priv: "{{ mysql_db }}.*:ALL" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}" ufw: rule: allow port: "{{ http_port }}" proto: tcp tags: [ system ] # WordPress Configuration - name: Download and unpack latest WordPress unarchive: src: https://wordpress.org/latest.tar.gz dest: "/var/www/{{ http_host }}" remote_src: yes creates: "/var/www/{{ http_host }}/wordpress" tags: [ wordpress ] - name: Set ownership file: path: "/var/www/{{ http_host }}" state: directory recurse: yes owner: www-data group: www-data tags: [ wordpress ] - name: Set permissions for directories shell: "/usr/bin/find /var/www/{{ http_host }}/wordpress/ -type d -exec chmod 750 {} \\;" tags: [ wordpress ] - name: Set permissions for files
shell
shell: "/usr/bin/find /var/www/{{ http_host }}/wordpress/ -type f -exec chmod 640 {} \\;" tags: [ wordpress ]
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
######################################################### # DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP ######################################################### --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes tags: [ system ] - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] tags: [ system ] - name: Install PHP Extensions apt: name={{ item }} update_cache=yes state=latest loop: "{{ php_modules }}" tags: [ system ] # Apache Configuration - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "www-data" group: "www-data" mode: '0755' tags: [ apache ] - name: Set up Apache VirtualHost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache tags: [ apache ] - name: Enable rewrite module shell: /usr/sbin/a2enmod rewrite notify: Reload Apache tags: [ apache ] - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache tags: [ apache ] - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf notify: Restart Apache tags: [ apache ] # MySQL Configuration - name: Set the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock tags: [ mysql, mysql-root ] - name: Remove all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Remove the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Creates database for WordPress mysql_db: name: "{{ mysql_db }}" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] - name: Create MySQL user for WordPress mysql_user: name: "{{ mysql_user }}" password: "{{ mysql_password }}" priv: "{{ mysql_db }}.*:ALL" state: present login_user: root login_password: "{{ mysql_root_password }}" tags: [ mysql ] # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}" ufw: rule: allow port: "{{ http_port }}" proto: tcp tags: [ system ] # WordPress Configuration - name: Download and unpack latest WordPress unarchive: src: https://wordpress.org/latest.tar.gz dest: "/var/www/{{ http_host }}" remote_src: yes creates: "/var/www/{{ http_host }}/wordpress" tags: [ wordpress ] - name: Set ownership file: path: "/var/www/{{ http_host }}" state: directory recurse: yes owner: www-data group: www-data tags: [ wordpress ] - name: Set permissions for directories shell: "/usr/bin/find /var/www/{{ http_host }}/wordpress/ -type d -exec chmod 750 {} \\;" tags: [ wordpress ] - name: Set permissions for files shell: "/usr/bin/find /var/www/{{ http_host }}/wordpress/ -type f -exec chmod 640 {} \\;" tags: [ wordpress ] - name: Set up wp-config
template
template: src: "files/wp-config.php.j2" dest: "/var/www/{{ http_host }}/wordpress/wp-config.php" tags: [ wordpress ] handlers:
wordpress-lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites
apt
apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ]
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install LEMP Packages
apt
apt: name={{ item }} update_cache=yes state=latest loop: [ 'nginx', 'mysql-server', 'python3-pymysql', 'php-fpm', 'php-mysql' ] # Nginx Configuration
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install LEMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'nginx', 'mysql-server', 'python3-pymysql', 'php-fpm', 'php-mysql' ] # Nginx Configuration - name: Sets Nginx conf file
template
template: src: "files/nginx.conf.j2" dest: "/etc/nginx/sites-available/{{ http_conf }}"
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install LEMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'nginx', 'mysql-server', 'python3-pymysql', 'php-fpm', 'php-mysql' ] # Nginx Configuration - name: Sets Nginx conf file template: src: "files/nginx.conf.j2" dest: "/etc/nginx/sites-available/{{ http_conf }}" - name: Enables new site
file
file: src: "/etc/nginx/sites-available/{{ http_conf }}" dest: "/etc/nginx/sites-enabled/{{ http_conf }}" state: link notify: Reload Nginx
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install LEMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'nginx', 'mysql-server', 'python3-pymysql', 'php-fpm', 'php-mysql' ] # Nginx Configuration - name: Sets Nginx conf file template: src: "files/nginx.conf.j2" dest: "/etc/nginx/sites-available/{{ http_conf }}" - name: Enables new site file: src: "/etc/nginx/sites-available/{{ http_conf }}" dest: "/etc/nginx/sites-enabled/{{ http_conf }}" state: link notify: Reload Nginx - name: Removes "default" site
file
file: path: "/etc/nginx/sites-enabled/default" state: absent notify: Reload Nginx # MySQL Configuration
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install LEMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'nginx', 'mysql-server', 'python3-pymysql', 'php-fpm', 'php-mysql' ] # Nginx Configuration - name: Sets Nginx conf file template: src: "files/nginx.conf.j2" dest: "/etc/nginx/sites-available/{{ http_conf }}" - name: Enables new site file: src: "/etc/nginx/sites-available/{{ http_conf }}" dest: "/etc/nginx/sites-enabled/{{ http_conf }}" state: link notify: Reload Nginx - name: Removes "default" site file: path: "/etc/nginx/sites-enabled/default" state: absent notify: Reload Nginx # MySQL Configuration - name: Sets the root password
mysql_user
mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install LEMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'nginx', 'mysql-server', 'python3-pymysql', 'php-fpm', 'php-mysql' ] # Nginx Configuration - name: Sets Nginx conf file template: src: "files/nginx.conf.j2" dest: "/etc/nginx/sites-available/{{ http_conf }}" - name: Enables new site file: src: "/etc/nginx/sites-available/{{ http_conf }}" dest: "/etc/nginx/sites-enabled/{{ http_conf }}" state: link notify: Reload Nginx - name: Removes "default" site file: path: "/etc/nginx/sites-enabled/default" state: absent notify: Reload Nginx # MySQL Configuration - name: Sets the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock - name: Removes all anonymous user accounts
mysql_user
mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}"
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install LEMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'nginx', 'mysql-server', 'python3-pymysql', 'php-fpm', 'php-mysql' ] # Nginx Configuration - name: Sets Nginx conf file template: src: "files/nginx.conf.j2" dest: "/etc/nginx/sites-available/{{ http_conf }}" - name: Enables new site file: src: "/etc/nginx/sites-available/{{ http_conf }}" dest: "/etc/nginx/sites-enabled/{{ http_conf }}" state: link notify: Reload Nginx - name: Removes "default" site file: path: "/etc/nginx/sites-enabled/default" state: absent notify: Reload Nginx # MySQL Configuration - name: Sets the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock - name: Removes all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" - name: Removes the MySQL test database
mysql_db
mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" # UFW Configuration
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install LEMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'nginx', 'mysql-server', 'python3-pymysql', 'php-fpm', 'php-mysql' ] # Nginx Configuration - name: Sets Nginx conf file template: src: "files/nginx.conf.j2" dest: "/etc/nginx/sites-available/{{ http_conf }}" - name: Enables new site file: src: "/etc/nginx/sites-available/{{ http_conf }}" dest: "/etc/nginx/sites-enabled/{{ http_conf }}" state: link notify: Reload Nginx - name: Removes "default" site file: path: "/etc/nginx/sites-enabled/default" state: absent notify: Reload Nginx # MySQL Configuration - name: Sets the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock - name: Removes all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" - name: Removes the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}"
ufw
" ufw: rule: allow port: "{{ http_port }}" proto: tcp # Sets Up PHP Info Page
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LEMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] - name: Install LEMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'nginx', 'mysql-server', 'python3-pymysql', 'php-fpm', 'php-mysql' ] # Nginx Configuration - name: Sets Nginx conf file template: src: "files/nginx.conf.j2" dest: "/etc/nginx/sites-available/{{ http_conf }}" - name: Enables new site file: src: "/etc/nginx/sites-available/{{ http_conf }}" dest: "/etc/nginx/sites-enabled/{{ http_conf }}" state: link notify: Reload Nginx - name: Removes "default" site file: path: "/etc/nginx/sites-enabled/default" state: absent notify: Reload Nginx # MySQL Configuration - name: Sets the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock - name: Removes all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" - name: Removes the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}" ufw: rule: allow port: "{{ http_port }}" proto: tcp # Sets Up PHP Info Page - name: Sets Up PHP Info Page
template
template: src: "files/info.php.j2" dest: "/var/www/html/info.php" handlers:
lemp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites
apt
apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages
apt
apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ]
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] - name: Create document root
file
file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755'
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Set up Apache virtualhost
template
template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache - name: Enable new site
shell
shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache - name: Disable default Apache site
shell
shell: /usr/sbin/a2dissite 000-default.conf when: disable_default notify: Reload Apache # MySQL Configuration
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf when: disable_default notify: Reload Apache # MySQL Configuration - name: Sets the root password
mysql_user
mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf when: disable_default notify: Reload Apache # MySQL Configuration - name: Sets the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock - name: Removes all anonymous user accounts
mysql_user
mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}"
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf when: disable_default notify: Reload Apache # MySQL Configuration - name: Sets the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock - name: Removes all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" - name: Removes the MySQL test database
mysql_db
mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" # UFW Configuration
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf when: disable_default notify: Reload Apache # MySQL Configuration - name: Sets the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock - name: Removes all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" - name: Removes the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}"
ufw
" ufw: rule: allow port: "{{ http_port }}" proto: tcp # PHP Info Page
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################## # DO Community Playbooks: LAMP on Ubuntu 18.04 ################################################## --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install prerequisites apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes loop: [ 'aptitude' ] #Apache Configuration - name: Install LAMP Packages apt: name={{ item }} update_cache=yes state=latest loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' - name: Set up Apache virtualhost template: src: "files/apache.conf.j2" dest: "/etc/apache2/sites-available/{{ http_conf }}" notify: Reload Apache - name: Enable new site shell: /usr/sbin/a2ensite {{ http_conf }} notify: Reload Apache - name: Disable default Apache site shell: /usr/sbin/a2dissite 000-default.conf when: disable_default notify: Reload Apache # MySQL Configuration - name: Sets the root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/run/mysqld/mysqld.sock - name: Removes all anonymous user accounts mysql_user: name: '' host_all: yes state: absent login_user: root login_password: "{{ mysql_root_password }}" - name: Removes the MySQL test database mysql_db: name: test state: absent login_user: root login_password: "{{ mysql_root_password }}" # UFW Configuration - name: "UFW - Allow HTTP on port {{ http_port }}" ufw: rule: allow port: "{{ http_port }}" proto: tcp # PHP Info Page - name: Sets Up PHP Info Page
template
template: src: "files/info.php.j2" dest: "/var/www/{{ http_host }}/info.php" handlers:
lamp_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites
apt
apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup - name: Make sure we have a 'wheel' group
group
group: name: wheel state: present
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup - name: Make sure we have a 'wheel' group group: name: wheel state: present - name: Allow 'wheel' group to have passwordless sudo
lineinfile
lineinfile: path: /etc/sudoers state: present regexp: '^%wheel' line: '%wheel ALL=(ALL) NOPASSWD: ALL' validate: '/usr/sbin/visudo -cf %s' # User + Key Setup
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup - name: Make sure we have a 'wheel' group group: name: wheel state: present - name: Allow 'wheel' group to have passwordless sudo lineinfile: path: /etc/sudoers state: present regexp: '^%wheel' line: '%wheel ALL=(ALL) NOPASSWD: ALL' validate: '/usr/sbin/visudo -cf %s' # User + Key Setup - name: Create a new regular user with sudo privileges
user
user: name: "{{ create_user }}" state: present groups: wheel append: true create_home: true shell: /bin/bash
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup - name: Make sure we have a 'wheel' group group: name: wheel state: present - name: Allow 'wheel' group to have passwordless sudo lineinfile: path: /etc/sudoers state: present regexp: '^%wheel' line: '%wheel ALL=(ALL) NOPASSWD: ALL' validate: '/usr/sbin/visudo -cf %s' # User + Key Setup - name: Create a new regular user with sudo privileges user: name: "{{ create_user }}" state: present groups: wheel append: true create_home: true shell: /bin/bash - name: Set authorized key for remote user
authorized_key
authorized_key: user: "{{ create_user }}" state: present key: "{{ copy_local_key }}"
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup - name: Make sure we have a 'wheel' group group: name: wheel state: present - name: Allow 'wheel' group to have passwordless sudo lineinfile: path: /etc/sudoers state: present regexp: '^%wheel' line: '%wheel ALL=(ALL) NOPASSWD: ALL' validate: '/usr/sbin/visudo -cf %s' # User + Key Setup - name: Create a new regular user with sudo privileges user: name: "{{ create_user }}" state: present groups: wheel append: true create_home: true shell: /bin/bash - name: Set authorized key for remote user authorized_key: user: "{{ create_user }}" state: present key: "{{ copy_local_key }}" - name: Disable password authentication for root
lineinfile
lineinfile: path: /etc/ssh/sshd_config state: present regexp: '^#?PermitRootLogin' line: 'PermitRootLogin prohibit-password' # Install Packages
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup - name: Make sure we have a 'wheel' group group: name: wheel state: present - name: Allow 'wheel' group to have passwordless sudo lineinfile: path: /etc/sudoers state: present regexp: '^%wheel' line: '%wheel ALL=(ALL) NOPASSWD: ALL' validate: '/usr/sbin/visudo -cf %s' # User + Key Setup - name: Create a new regular user with sudo privileges user: name: "{{ create_user }}" state: present groups: wheel append: true create_home: true shell: /bin/bash - name: Set authorized key for remote user authorized_key: user: "{{ create_user }}" state: present key: "{{ copy_local_key }}" - name: Disable password authentication for root lineinfile: path: /etc/ssh/sshd_config state: present regexp: '^#?PermitRootLogin' line: 'PermitRootLogin prohibit-password' # Install Packages - name: Update apt
apt
apt: update_cache=yes
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup - name: Make sure we have a 'wheel' group group: name: wheel state: present - name: Allow 'wheel' group to have passwordless sudo lineinfile: path: /etc/sudoers state: present regexp: '^%wheel' line: '%wheel ALL=(ALL) NOPASSWD: ALL' validate: '/usr/sbin/visudo -cf %s' # User + Key Setup - name: Create a new regular user with sudo privileges user: name: "{{ create_user }}" state: present groups: wheel append: true create_home: true shell: /bin/bash - name: Set authorized key for remote user authorized_key: user: "{{ create_user }}" state: present key: "{{ copy_local_key }}" - name: Disable password authentication for root lineinfile: path: /etc/ssh/sshd_config state: present regexp: '^#?PermitRootLogin' line: 'PermitRootLogin prohibit-password' # Install Packages - name: Update apt apt: update_cache=yes - name: Install required system packages
apt
apt: name={{ sys_packages }} state=latest # UFW Setup
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup - name: Make sure we have a 'wheel' group group: name: wheel state: present - name: Allow 'wheel' group to have passwordless sudo lineinfile: path: /etc/sudoers state: present regexp: '^%wheel' line: '%wheel ALL=(ALL) NOPASSWD: ALL' validate: '/usr/sbin/visudo -cf %s' # User + Key Setup - name: Create a new regular user with sudo privileges user: name: "{{ create_user }}" state: present groups: wheel append: true create_home: true shell: /bin/bash - name: Set authorized key for remote user authorized_key: user: "{{ create_user }}" state: present key: "{{ copy_local_key }}" - name: Disable password authentication for root lineinfile: path: /etc/ssh/sshd_config state: present regexp: '^#?PermitRootLogin' line: 'PermitRootLogin prohibit-password' # Install Packages - name: Update apt apt: update_cache=yes - name: Install required system packages apt: name={{ sys_packages }} state=latest # UFW Setup - name: UFW - Allow SSH connections
ufw
ufw: rule: allow name: OpenSSH
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks
################################################# # DO Community Playbooks: Initial Server Setup ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Install Prerequisites apt: name=aptitude update_cache=yes state=latest force_apt_get=yes # Sudo Group Setup - name: Make sure we have a 'wheel' group group: name: wheel state: present - name: Allow 'wheel' group to have passwordless sudo lineinfile: path: /etc/sudoers state: present regexp: '^%wheel' line: '%wheel ALL=(ALL) NOPASSWD: ALL' validate: '/usr/sbin/visudo -cf %s' # User + Key Setup - name: Create a new regular user with sudo privileges user: name: "{{ create_user }}" state: present groups: wheel append: true create_home: true shell: /bin/bash - name: Set authorized key for remote user authorized_key: user: "{{ create_user }}" state: present key: "{{ copy_local_key }}" - name: Disable password authentication for root lineinfile: path: /etc/ssh/sshd_config state: present regexp: '^#?PermitRootLogin' line: 'PermitRootLogin prohibit-password' # Install Packages - name: Update apt apt: update_cache=yes - name: Install required system packages apt: name={{ sys_packages }} state=latest # UFW Setup - name: UFW - Allow SSH connections ufw: rule: allow name: OpenSSH - name: UFW - Deny all other incoming traffic by default
ufw
ufw: state: enabled policy: deny direction: incoming
setup_ubuntu1804/playbook.yml
ansible-playbooks
https://github.com/do-community/ansible-playbooks