Ansible 1.6.2では特に設定不要だそうです (2014-05-28追記) Ansibleチートシート(実行周り) - Qiitaの「ローカルでの実行」によるとAnsible 1.6.2では特に下記のような設定は不要だそうです。 以下元記事 ymlにconnection: localと書いておけば、わざわざlocalhostにsshで繋ぐことなくlocalhostで実行出来ます。コマンドラインで--connection=localと指定する手もあるそうです。
モジュール化されていない場合はCommandかShellモジュールで実行するOSコマンドを記述する。 基本的にはCommandを利用するように推奨されているが、パイプやらリダイレクトやらがある場合はShellモジュールを利用する。 複数行記述するにはどうするか? 下記のように;で区切って並べるとよい。 ;を入れないと続きとみなされるので注意。 - name: git clone and rbenv shell: > git clone https://github.com/sstephenson/rbenv.git ~/.rbenv; git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build; echo 'export PATH="$HOME/.rbenv/bin:$PATH"'
※Ansible を始めて日が浅いので最新のバージョン(1.7.2)でしかチェックしていません。 ※CentOSでしか確認していません。誰か他のOSでチェックしたらコメントに残してくれるとみんな助かっていいと思う。 ぐぐって出てくる方法だと shell: や command: モジュールを使って(-f とかちょっと。。。)チェックした値を register: していて、なんだかなぁと思っていたのだけど、正しい判断の仕方が見つけられた(と思う)のでメモしてみる。(実はQiita投稿は初めてw) よく見ると本家ドキュメントにも書いてあって、コアモジュールの stat を使うだけ。 # task - stat: path=/hoge/fuga register: is_file - name: skip if file is found. fail: msg='file not found' w
Ansible¶ 目次Ansible主な構成と必要なツールバージョンAnsible 2.1Ansible 2.0 Ansible制御マシン側の設定SSH接続のエラー(Host fingerprint)Windowsを管理ノードとするときの制御ホスト側の設定python 2.7.10以降でWindows管理ノードとWinRM通信するときの自己署名証明書対応設定 Ansible管理ノード(制御される側)の設定条件Windows OS(全般)WinRM 4.0のインストール(Windows 7, 2008)Windows準備作業 playbookを作るYAMLの書き方メモファイル分割ベストプラクティス構造単一ファイル構成 モジュールcommandかshellか GATHERING FACTをスキップして実行時間を短縮 逆引きタスク被制御側マシン上で特定のユーザーとして処理を実行したい制御側マシン
なぜタグ付けをするか タスクが増えてくると毎回全タスクを実行していると時間がかかります。 ネットワークが遅いと待ち時間にイライラすることになり、 精神衛生的によくありませんね。 そこでタグ機能です。 タスクにタグ付けをしておけば、 対象のタスクだけを実行することができます。 タグ付け ansibleで仮想マシンにnginxを入れる 上記をもとに説明していきます。 local.ymlがplaybookにあたります。 ではでは、local.ymlの中身を見てみましょう。 --- # file: provisioning/local.yml - name: Nginx Playbook # タスク名 hosts: local # 対象ホスト sudo: yes # sudoするか roles: # 実際のタスクを記述しているディレクトリ - nginx tags: # タスクをタグ付け - ng
when による条件分岐について調べたのでまとめておきます。 host の情報や他のコマンドの実行結果の値により実行する task を定義する事が出来ます。 task を実行するための条件は when 句で指定します。 when 句では変数を指定できるので、例えば --extra-vars を使用して以下のように外部から実行条件を指定する事ができます。 when.yml --- - user: root hosts: all tasks: - name: install mlocate yum: name=mlocate state=installed when: install == "y" when 句での変数の参照には ${} や {{}} は付けない事に注意。 実行時には以下のように変数 install の値を渡します。 「y」以外の値を渡すと task の実行が skip される
ansibleで実行対象を切り替える方法¶ 本番環境、検証環境、開発環境など、複数の環境を持っており、それごとにサー バーや設定が異なる、ということはよくあると思います。 ansibleで、これらの対象を切り替える方法は複数ありますので、それを紹介 したいと思います。 サーバーが異なるだけで、設定が同じ場合¶ この場合は、inventoryファイルでグループを分けて切りかえればいいと思い ます。 [stg:children] stg_Web stg_DB [prod:children] prod_Web prod_DB [stg_web] stg_web_01 [stg_DB] stg_db_01 [prod_web] prod_web_01 [prod_DB] prod_db_01
渡辺です。 セキュリティを高めるなどの理由で対象インスタンスにEIPを付与しない場合、SSHは踏み台(Bastion)経由となります(参考: Amazon VPC環境にメンテナンス用の踏み台サーバを構築する)。 踏み台サーバのある構成でAnsibleを利用する場合、ansible.cnfのssh_connectionでssh_argsを設定しましょう。 ssh_configの準備 はじめにsshのconfigファイルを作成します。 これは、~/.ssh/configに設定するファイルの一部と考えて良いでしょう。 Ansibleのファイルと一緒にバージョン管理する方が良いと思うので、Ansibleのプロジェクトルートにおくことをおすすめします。 Host bastion HostName 52.52.xxx.xxx User ec2-user IdentityFile ~/.ssh/prd.
サーバがだいたい CentOS 5/6 でsshの設定においてSFTPがオフになっていると、ansibleを使おうとしたときにいきなりファイル転送ができなくてハマる。 まず第一に、RHEL6およびそれ以前において OpenSSH が ControlPersist オプションをサポートしていないため、ansibleは paramiko というライブラリを使おうとする。 When using Enterprise Linux 6 operating systems as the control machine (Red Hat Enterprise Linux and derivatives such as CentOS), however, the version of OpenSSH may be too old to support ControlPersist. On these op
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く