ansible 及相关应用

ansible 及相关应用

(.py3-a2.5-env) [deploy@ansible ~]$ pwd

/home/deploy

(.py3-a2.5-env) [deploy@ansible ~]$ cd test_playbooks/

(.py3-a2.5-env) [deploy@ansible test_playbooks]$ tree ./

./

├── deploy.yml

├── inventory

│ └── testenv

└── roles

└── testbox

└── tasks

└── main.yml

4 directories, 4 files

(.py3-a2.5-env) [deploy@ansible test_playbooks]$ cat deploy.yml - hosts: "testservers" gather_facts: true remote_user: root roles: - testbox

(.py3-a2.5-env) [deploy@ansible test_playbooks]$ cat inventory/testenv [testservers]test.example.com

[testservers:vars]server_name=test.example.comuser=rootoutput=/root/test.txt

(.py3-a2.5-env) [deploy@ansible test_playbooks]$ cat roles/testbox/tasks/main.yml - name: Print server name and user to remote testbox shell: "echo 'Currently {{ user }} is logining {{ server_name }} > {{ output }}'"

执行 ansible-playbook

(.py3-a2.5-env) [deploy@ansible test_playbooks]$ ansible-playbook -i inventory/testenv ./deploy.yml

PLAY [testservers] ***************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************ok: [test.example.com]

TASK [testbox : Print server name and user to remote testbox] ********************************************************************************************************************changed: [test.example.com]

PLAY RECAP ***********************************************************************************************************************************************************************test.example.com : ok=2 changed=1 unreachable=0 failed=0

登录目标主机查看结果

(.py3-a2.5-env) [deploy@ansible test_playbooks]$ ssh root@test.example.comLast login: Sun Feb 7 15:30:00 2021 from 192.168.11.09[root@testbox ~]# lsbak test.txt[root@testbox ~]# cat test.txt Currently root is logining test.example.com #执行playbook 成功后的结果

关于作者: admin

相关推荐

刘姓姓氏起源与刘姓人口繁衍

刘姓姓氏起源与刘姓人口繁衍

365平台官方版下载 08-14
玫瑰小镇任务-最新攻略与奖励介绍 玫瑰小镇主线及支线任务合集
加州卫生部门公开乔布斯死因鉴定

加州卫生部门公开乔布斯死因鉴定

365足球外围网站官网 08-11