Ansible実践ガイド(第3版) を読んで [個人メモ]

Chapter 2

  • virtualenv (p.57)
$ sudo pip install --upgrade pip
$ sudo pip install virtualenv
$ virtualenv $HOME/venv1
$ source $HOME/venv1/bin/activate # 仮想環境の有効化
$ deactivate # 仮想環境の無効化
  • $HOME/effective_ansible/sec2/inventory.ini の設定 (p.62)
    • ansible_user で Hostname に ssh するユーザ名を指定する必要がある。
    • ポート番号は 22 以外なら指定必須
[test_servers]
Hostname:Port ansible_user=User
  • ユーザ追加は ssh でも可能 (p.65)
$ ansible -i inventory.ini test_servers -m userr -Kb -a 'user=user01 append=yes comment="hoge"' # 要求される BECOME password は ssh 先の管理者パスワード
  • copy file について (p.66)
- hosts: test_servers
  tasks:
  - name: copy file
    copy:
      src: /etc/hosts # これはコントロールノードのファイル
      dest: /home/ansible/tmp/hosts # これは test_servers の位置
      owner: ansible # ansible_ssh_user と一致しないと chown failed となるようである
      mode: 0644