#author("2020-05-23T09:27:04+09:00","default:tanak0to","tanak0to")
#author("2020-05-23T10:01:56+09:00","default:tanak0to","tanak0to")
RIGHT:[[Mac 関係覚え書き]]

*インストール [#q8cf0f84]
環境: macOS 10.15.4

Ansible は homebrew でインストール.
 $ brew install ansible

Python は /usr/local/opt 以下に brew の python 3.8 がインストールされ,
それが使われるようだ.

/usr/local/bin には Python3.8 はシンボリックリンクされないので,
OS 標準の Python 3.7 との関係がややこしい.

*実行 [#fa4fb45c]
他のサーバを管理するには公開鍵暗号で ssh 接続できる必要あり.
homebrew では sshkey をインストールしないポリシーのようだ.
homebrew では sshpass をインストールしないポリシーのようだ.

 ~/Ansible/
 に inventory ファイル,Playbook ファイル,var ファイルのサンプルを作った.
に inventory ファイル,Playbook ファイル,var ファイルのサンプルを作った.

 ~/Ansible/
 ├── ansible.cfg
 ├── group_vars
 │   └── aws.yml
 ├── inventory
 ├── pb_aws_cmd.yml
 └── pb_aws_updata.yml

 % ansible-playbook -i inventory pb_aws_cmd.yml
で AWS の EC2 にコマンドを打てることを確認.

**ansible.cfg [#ee87f898]
 [defaults]
 host_key_checking = False
 interpreter_python=auto_silent

**aws.yml [#w8a77fad]
 ansible_ssh_private_key_file: ~/.ssh/aws.pem
 ansible_user: hoge

**inventory [#j996c6d5]
 [localhost]
 127.0.0.1 ansible_connection=local
 
 [localhost:vars]
 ansible_python_interpreter=/usr/local/Cellar/ansible/2.9.7/libexec/bin/python3.8
 
 [aws]
 aws.example.com

**pb_aws_cmd.yml [#h4d3e877]
Software Design 2018 12月号のサンプルより
 - hosts: aws
   vars:
     sample_vars: software_design_2018
   tasks:
     - shell: uptime
       register: result
 
     - debug:
         msg: "{{ result.stdout }}"
 
     - debug:
         msg: "{{ sample_vars }}"

**pb_aws_update.yml [#w5aa1bda]
apt upgrade  を実行する Playbook(インデントに注意)
 - hosts: aws
   become: true
   become_user: root
   tasks:
     - name: Update apt repo and cache on all Debian/Ubuntu boxes
       apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
 
     - name: Upgrade all packages on servers
       apt: upgrade=dist force_apt_get=yes
 
     - name: Check if a reboot is needed on all servers
       register: reboot_required_file
       stat: path=/var/run/reboot-required get_md5=no
 
     - name: Reboot the box if kernel updated
       reboot:
         msg: "Reboot initiated by Ansible for kernel updates"
         connect_timeout: 5
         reboot_timeout: 300
         pre_reboot_delay: 0
         post_reboot_delay: 30
         test_command: uptime
       when: reboot_required_file.stat.exists


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS