Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to run orawls as non-root user #343

Merged
merged 5 commits into from
Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ For all WebLogic or FMW versions
## Puppet master with orawls module key points
it should work on every PE or opensource puppet master, customers and I successfully tested orawls on PE 3.0, 3.1, 3.2, 3.3. See also the puppet master vagrant box

For Running orawls module without root/elevated privileges, please use v3.7.0 or higher

But when it fails you can do the following actions.
- Check the time difference/timezone between all the puppet master and agent machines.
- Update orawls and its dependencies on the puppet master.
Expand All @@ -203,6 +205,16 @@ Contains WebLogic Facter which displays the following
default this orawls module uses oracle as weblogic install user
you can override this by setting the following fact 'override_weblogic_user', like override_weblogic_user=wls or set FACTER_override_weblogic_user=wls

## Override the default file location where orawls saves domain & other settings (Applicable for running as non-root user)

default this orawls module saves the domain & connection related setting in /etc in yaml format
you can override this by setting the following 2 facts:
for domain information: override_wls_domains_file=[custom_path]/wls_domains.yaml
or set FACTER_override_wls_domains_file=[custom_path]/wls_domains.yaml

for settings infortmation: override_wls_setting_file=[custom_path]/wls_setting.yaml
or set FACTER_override_wls_setting_file=[custom_path]/wls_setting.yaml

## Override the default WebLogic domain folder

Set the following hiera parameters for weblogic.pp
Expand Down
17 changes: 15 additions & 2 deletions lib/facter/orawls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,22 @@ def get_domains(domain_folder, count_domains)
count_domains
end

# get wls_domains.yaml file location if overridden
def get_wls_domains_file
wls_domains_file = Facter.value('override_wls_domains_file')
if wls_domains_file.nil?
Puppet.debug 'wls_domains_file is default to /etc/wls_domains.yaml'
else
Puppet.debug "wls_domains_file is overridden to #{wls_domains_file}"
return wls_domains_file
end
'/etc/wls_domains.yaml'
end

# read the domains yaml and analyze domain
begin
entries = YAML.load(File.open('/etc/wls_domains.yaml'))
wls_domains_file = get_wls_domains_file
entries = YAML.load(File.open(wls_domains_file))
unless entries.nil?
domains = entries['domains']
unless domains.nil?
Expand All @@ -795,7 +808,7 @@ def get_domains(domain_folder, count_domains)
end
end
rescue
Puppet.debug '/etc/wls_domains.yaml not found'
Puppet.debug "#{wls_domains_file} not found"
end

Facter.add('ora_mdw_domain_cnt') do
Expand Down
16 changes: 13 additions & 3 deletions lib/puppet/type/wls_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
module Puppet
Type.newtype(:wls_setting) do
include EasyType

def self.get_wls_setting_file
wls_setting_file = Facter.value('override_wls_setting_file')
if wls_setting_file.nil?
Puppet.debug 'wls_setting_file is default to /etc/wls_setting.yaml'
else
Puppet.debug "wls_setting_file is overridden to #{wls_setting_file}"
return wls_setting_file
end
'/etc/wls_setting.yaml'
end

DEFAULT_FILE = '/etc/wls_setting.yaml'
DEFAULT_FILE = get_wls_setting_file

desc 'This resource allows you to set the defaults for all other wls types'

Expand Down Expand Up @@ -53,7 +64,7 @@ def self.read_from_yaml
{}
end
end

private

def self.normalize(content)
Expand All @@ -72,6 +83,5 @@ def self.with_hashified_keys(hash)
end
result
end

end
end
11 changes: 11 additions & 0 deletions lib/utils/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ def read_from_yaml
Hash['default', {}]
end
end

def get_wls_setting_file
wls_setting_file = Facter.value('override_wls_setting_file')
if wls_setting_file.nil?
Puppet.debug 'wls_setting_file is default to /etc/wls_setting.yaml'
else
Puppet.debug "wls_setting_file is overridden to #{wls_setting_file}"
return wls_setting_file
end
'/etc/wls_setting.yaml'
end
end
15 changes: 12 additions & 3 deletions lib/utils/wls_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Utils
module WlsAccess
include Settings

DEFAULT_FILE = '/etc/wls_setting.yaml'
DEFAULT_FILE = get_wls_setting_file

def self.included(parent)
parent.extend(WlsAccess)
Expand Down Expand Up @@ -324,16 +324,25 @@ def execute_wlst(script, tmpFile, parameters, domain, domainValues, options = {}
fail('weblogic_password cannot be nil, check the wls_setting resource type') if weblogicPassword.nil?

debugmode = Puppet::Util::Log.level

if Puppet.features.root?
eval_operatingSystemUser = operatingSystemUser
end

if debugmode.to_s == 'debug'
puts 'Prepare to run: ' + tmpFile.path + ',' + operatingSystemUser + ',' + domain + ',' + weblogicHomeDir + ',' + weblogicUser + ',' + weblogicPassword + ',' + weblogicConnectUrl
if eval_operatingSystemUser
puts 'Prepare to run: ' + tmpFile.path + ',' + eval_operatingSystemUser + ',' + domain + ',' + weblogicHomeDir + ',' + weblogicUser + ',' + weblogicPassword + ',' + weblogicConnectUrL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weblogicConnectUrL typo?

Copy link
Contributor

@alexjfisher alexjfisher Jul 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #353

else
puts 'Prepare to run: ' + tmpFile.path + ',' + domain + ',' + weblogicHomeDir + ',' + weblogicUser + ',' + weblogicPassword + ',' + weblogicConnectUrl
end
puts 'vvv==================================================================='
File.open(tmpFile.path).readlines.each do |line|
puts line
end
puts '^^^===================================================================='
end

wls_daemon = WlsDaemon.run(operatingSystemUser, domain, weblogicHomeDir, weblogicUser, weblogicPassword, weblogicConnectUrl, postClasspath, custom_trust, trust_keystore_file, trust_keystore_passphrase, use_default_value_when_empty)
wls_daemon = WlsDaemon.run(eval_operatingSystemUser, domain, weblogicHomeDir, weblogicUser, weblogicPassword, weblogicConnectUrl, postClasspath, custom_trust, trust_keystore_file, trust_keystore_passphrase, use_default_value_when_empty)

if debug_module.to_s == 'true'
if !File.directory?(archive_path)
Expand Down
9 changes: 8 additions & 1 deletion manifests/copydomain.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@
$log_dir = hiera('wls_log_dir' , undef), # /data/logs
$log_output = false, # true|false
$server_start_mode = 'dev', # dev/prod
$wls_domains_file = $override_wls_domains_file,
)
{
if ( $wls_domains_file == undef or $wls_domains_file == '' ){
$wls_domains_file_location = '/etc/wls_domains.yaml'
} else {
$wls_domains_file_location = $wls_domains_file
}

if ( $wls_domains_dir == undef or $wls_domains_dir == '' ) {
$domains_dir = "${middleware_home_dir}/user_projects/domains"
} else {
Expand Down Expand Up @@ -182,7 +189,7 @@
}

yaml_setting { "domain ${title}":
target => '/etc/wls_domains.yaml',
target => $wls_domains_file_location,
key => "domains/${domain_name}",
value => "${domains_dir}/${domain_name}",
}
Expand Down
11 changes: 9 additions & 2 deletions manifests/domain.pp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@
$ohs_standalone_listen_address = undef,
$ohs_standalone_listen_port = undef,
$ohs_standalone_ssl_listen_port = undef,
$wls_domains_file = $override_wls_domains_file,
)
{
if ( $wls_domains_file == undef or $wls_domains_file == '' ){
$wls_domains_file_location = '/etc/wls_domains.yaml'
} else {
$wls_domains_file_location = $wls_domains_file
}

if ( $wls_domains_dir == undef or $wls_domains_dir == '' ) {
$domains_dir = "${middleware_home_dir}/user_projects/domains"
} else {
Expand Down Expand Up @@ -405,7 +412,7 @@
exec { "create ${log_dir} directory":
command => "mkdir -p ${log_dir}",
unless => "test -d ${log_dir}",
user => 'root',
user => $os_user,
path => $exec_path,
}
}
Expand Down Expand Up @@ -590,7 +597,7 @@
}

yaml_setting { "domain ${title}":
target => '/etc/wls_domains.yaml',
target => $wls_domains_file_location,
key => "domains/${domain_name}",
value => $domain_dir,
require => Exec["execwlst ${domain_name} ${title}"],
Expand Down