Last active
December 22, 2018 13:00
-
-
Save Kento75/07192e2ddf6b8770f584e547deb5bc39 to your computer and use it in GitHub Desktop.
【備忘録】Ansible② Playbookとインベントリの書き方 ref: https://qiita.com/Kento75/items/a5e89c5034200310f98f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo amazon-linux-extras install -y ansible2 | |
$ ansible --version | |
ansible 2.x.x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vi ~/sample.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: group1 # ここでグループを指定 | |
vars: | |
sample_args: "書き換えられる文字列" | |
tasks: # tasks で定義された内容が実行される | |
- debug: | |
msg: "{{ sample_args }}" # 変数を展開する場合 "{{}}" を使用する | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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