Ansibleの最初の一歩の手前

 人様の作ったplaybookバクって自動化 (゚д゚)ウマー、ってしたいんですけど
最初の一歩がダメダメです*1

こちらのGitLab用playbookを使って

% ansible-playbook site.yml -i hosts -k


を実行してみるも"msg: You need to be root to perform this command."っとインストール途中で失敗><


ansibleのインストール、成功

debian*2でapt-getでインストール

hostsの準備

構成管理したい対象PC*3の情報をhostsファイルに記載

hostsサンプル

[server]
50.x.x.x ansible_ssh_port=22 ansible_ssh_user=murase

ssh_portやssh_userはこちらに書かなくても、/etc/ansibleの方に一括記載も出来る

pingの確認、は成功

$ ansible all -i hosts -m ping
50.x.x.x | success >> {
    "changed": false, 
    "ping": "pong"
}

yumの確認、で失敗

 最初はroot権限で実行しろ、ってエラーなったので

$ ansible all -i hosts  -m yum -a "name=htop state=latest" -k 
SSH password: 
50.x.x.x | FAILED >> {
    "changed": false, 
    "failed": true, 
    "msg": "You need to be root to perform this command.\n", 
    "rc": 1, 
    "results": [
        "Loaded plugins: fastestmirror, security\n"
    ]
}


 sudo権限もってるユーザと、パスワード確認オプションを追加でyumインストール成功。

$ ansible all -i hosts -u murase --ask-sudo-pass -m yum -a "name=htop state=latest" -k 
SSH password: 
sudo password [defaults to SSH password]: 
50.x.x.x | success >> {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror, security\n.....
    ]
}


 yumでのアンインストールも成功。

$ ansible all -i hosts -u murase --ask-sudo-pass -m yum -a "name=htop state=removed" -k 
SSH password: 
sudo password [defaults to SSH password]: 
50.x.x.x | success >> {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror, security\n....
    ]
}

ansible-playbook再挑戦

なので、"-u murase --ask-sudo-pass"をつけて再挑戦してみるも結果変わらず失敗。

diff --git a/gitlab/site.yml b/gitlab/site.yml
index 96b0026..360418c 100644
--- a/gitlab/site.yml
+++ b/gitlab/site.yml
@@ -1,7 +1,8 @@
 ---
 - name: Install GitLab
   hosts: gitlab-server
-  user: root
+  user: murase
+  sudo_user: murase
+  sudo: yes
 
   roles:
     - common

で、上記のとおりsite.yml編集してみても失敗。

進捗ダメでした

 以上、実行まで道は遠いwー、

*1:大人しくchefでも使ってればw;

*2:sid

*3:サーバ