1. 配置ansible 使用paramiko进行链接(ssh 有卡死问题, 等待反馈.)

2. 修复freebsd 推送带sudo规则的用户时 由于 sed  引起的问题。
pull/71/head
yumaojun 2016-02-23 11:48:09 +08:00
parent 7bef517518
commit 4645029a27
2 changed files with 15 additions and 4 deletions

View File

@ -125,7 +125,7 @@ class MyRunner(MyInventory):
self.results_raw = {}
def run(self, module_name='shell', module_args='', timeout=10, forks=10, pattern='*',
become=False, become_method='sudo', become_user='root', become_pass=''):
become=False, become_method='sudo', become_user='root', become_pass='', transport='paramiko'):
"""
run module from andible ad-hoc.
module_name: ansible module_name
@ -140,7 +140,8 @@ class MyRunner(MyInventory):
become=become,
become_method=become_method,
become_user=become_user,
become_pass=become_pass
become_pass=become_pass,
transport=transport
)
self.results_raw = hoc.run()
logger.debug(self.results_raw)

View File

@ -13,7 +13,12 @@ add_cmd_alias() {
{% for sudo_name, sudo_cmd in sudo_alias.items %}
{% if sudo_name != 'ALL' %}
if $(grep '^Cmnd_Alias \<{{ sudo_name }}\>' ${sudo_file} &> /dev/null); then
isbsd=$(uname -a | grep -i 'freebsd' &> /dev/null && echo "yes" || echo "no")
if [ $isbsd == "yes" ]; then
sed -i .bk 's@^Cmnd_Alias \<{{ sudo_name }}\>.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file}
else
sed -i 's@^Cmnd_Alias \<{{ sudo_name }}\>.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file}
fi
else
echo "Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}" >> ${sudo_file}
fi
@ -27,7 +32,12 @@ add_role_chosen() {
sudo_file=$1
{% for user, alias in sudo_user.items %}
if $(grep '^{{ user }}\>' ${sudo_file} &> /dev/null); then
isbsd=$(uname -a | grep -i 'freebsd' &> /dev/null && echo "yes" || echo "no")
if [ $isbsd == "yes" ]; then
sed -i .bk 's@^{{ user }}\>.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file}
else
sed -i 's@^{{ user }}\>.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file}
fi
else
echo "{{ user }} ALL = (root) NOPASSWD: {{ alias }}" >> ${sudo_file}
fi