Ansibleを触っていて困ったのは、既存のサーバ群のセキュリティが強固な時でした。
強固というか、sudoersに各シェル(sh,bash)を使わせない設定になっていたので
Ansibleの挙動的に、指定されたシェルを使ってrootにスイッチ?かsudoを叩いていたのですが
どうやらそれにひっかかっていた模様・・・
Ansibleの設定でどうこう、では無く力技で回避させたので備忘録で残しておきます。
usesudo.sh
# !/bin/sh
### 引数にsudoで実行したいコマンドを引き渡す
password=yourpassword
expect -c "
spawn sudo $*
set timeout 30
expect password:
send $password
"
executewithsudo.yml
- hosts: sample
user: user
sudo: no
tasks:
- name: copy "usesudo.sh"
copy: src=/tmp/usesudo.sh dest=/tmp/usesudo.sh
- name: chmod
command: chmod +x /tmp/usesudo.sh
- name: execute command
command: /tmp/usesudo.sh "yum update bash -y"
- name: remove dangerous file
file: path=/tmp/usesudo.sh state=absent
しかしshも使わせない設計とは・・・