Skip to content

Instantly share code, notes, and snippets.

@Kento75
Last active December 22, 2018 13:00
Show Gist options
  • Save Kento75/07192e2ddf6b8770f584e547deb5bc39 to your computer and use it in GitHub Desktop.
Save Kento75/07192e2ddf6b8770f584e547deb5bc39 to your computer and use it in GitHub Desktop.
【備忘録】Ansible② Playbookとインベントリの書き方 ref: https://qiita.com/Kento75/items/a5e89c5034200310f98f
$ sudo amazon-linux-extras install -y ansible2
$ ansible --version
ansible 2.x.x
[defaults]
# some basic default values...
↓ この行がコメントアウトされているので#を削除する
inventory = /etc/ansible/hosts
#library = /usr/share/my_modules/
#module_utils = /usr/share/my_module_utils/
#remote_tmp = ~/.ansible/tmp
#local_tmp = ~/.ansible/tmp
#forks = 5
#poll_interval = 15
#sudo_user = root
#ask_sudo_pass = True
#ask_pass = True
#transport = smart
#remote_port = 22
[group1]
127.0.0.1 ansible_connection=local
[group2]
127.0.0.1 ansible_connection=local
[nodes]
node-1 ansible_host=127.0.0.1 ansible_connection=local
node-2 ansible_host=127.0.0.1 ansible_connection=local
vi ~/sample.yml
- hosts: group1 # ここでグループを指定
vars:
sample_args: "書き換えられる文字列"
tasks: # tasks で定義された内容が実行される
- debug:
msg: "{{ sample_args }}" # 変数を展開する場合 "{{}}" を使用する
$ ansible-playbook sample.yml -e 'sample_args=上書き後の文字 列'
PLAY [group1] ***************************************************************************
TASK [Gathering Facts] ******************************************************************
ok: [127.0.0.1]
TASK [debug] ****************************************************************************
ok: [127.0.0.1] => {
"msg": "上書き後の文字列"
}
PLAY RECAP ******************************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0
ansible-playbook sample.yml
PLAY [group1] ***************************************************************************
TASK [Gathering Facts] ******************************************************************
ok: [127.0.0.1]
TASK [debug] ****************************************************************************
ok: [127.0.0.1] => {
"msg": "書き換えられる文字列"
}
PLAY RECAP ******************************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment