Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

AnsibleのroleやTips

More than 5 years have passed since last update.

参考

sshのポートが22でない場合

hosts
[web_all]
wwwsrv1 ansible_ssh_port=12345

モジュール一覧表示

ansible-doc -l

気になるモジュール

  • locale_gen
  • postgresql_db
  • postgresql_privs
  • postgresql_user

serverの状態をチェック

書き方
- assert: { that: "ansible_os_family != 'RedHat'" }
書き方2
- assert: {
  that:
    "ansible_os_family != 'RedHat'"
  }

ansibleを実行すると、結果を$?で取得できる。
(正常終了: 0、異常終了: 1以上)

role入門してみた

  • run.sh
  • main.yml
  • vim/tasks/main.yml

というファイル構成の場合、

main.yml
---
- hosts: localhost
  sudo: yes
  roles:
    - role: vim
vim/tasks/main.yml
---
- name: install vim
  yum: name=vim state=latest
run.sh
test -z $(which ansible-playbook) && sudo yum install -y epel-release && sudo yum install -y ansible
ansible-playbook --diff -vv main.yml

role入門2

  • tasks,vars,handlersを使う
php/tasks/main.yml
---
- name: find {{ php_log }}
  stat: path={{ php_log }}
  register: result

- name: create {{ php_log }}
  file: path={{ php_log }} owner=apache group=apache mode=0644 state=touch
  when: not result.stat.exists

- name: install php5.6
  yum: pkg={{ item }} state=installed enablerepo=remi
  with_items:
    - php56
    - php56-php-devel
    - php56-php-mysqlnd
    - php56-php-mbstring
    - php56-php-gd
    - php56-php-cli
  notify:
    - restart httpd
php/handlers/main.yml
---
- name: restart httpd
  service: name=httpd state=restarted
php/vars/main.yml
---
php_log: /var/log/php.log

role入門3 filesを使う

  • php/files/php.ini を用意。
php/tasks/main.yml
- copy: >
    src=php.ini
    dest=/etc/php.ini

こういうふうに書ける。

行の追加(lineinfile)

os/tasks/main.yml
---
- name: CentOS6,7の名前解決高速化
  lineinfile: dest=/etc/resolv.conf line='options single-request-reopen'

- name: kernelが更新されてvirtualbox guest addinsが使えなくなることの対策
  lineinfile: dest=/etc/yum.conf line='exclude=kernel-[23]*'
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away