当前位置:网站首页>Ansible practical Series II_ Getting started with Playbook
Ansible practical Series II_ Getting started with Playbook
2022-07-06 10:56:00 【hyh123a】
Preface
demand : Operate multiple hosts , by Kubespray Do matting
Environmental Science
Ubuntu 20.04
1、 command
-k(–ask-pass) For interactive input ssh password
-K(-ask-become-pass) For interactive input sudo password
-u Designated user
# ansible-playbook a.yml --syntax-check # Check yaml Is the syntax of the file correct
# ansible-playbook a.yml --list-task # Check tasks Mission
# ansible-playbook a.yml --list-hosts # Check the active host
# ansible-playbook a.yml --start-at-task='Copy Nginx.conf' # Designate from a task Began to run
2、 Example
demo 1: How to get started
- edit
sudo nano demo1.yaml
# Revised as follows
- hosts: 172.16.106.20 # Designated host
remote_user: ubuntu20 # Specifies the user who performs tasks on the managed host
tasks: # Task list ↓
- name: hello world # Task name close firewall
command: 'echo hello world' # call command modular Execute the turn off firewall command
- perform
ansible-playbook demo1.yml --syntax-check
ansible-playbook demo1.yaml
- Output is as follows
PLAY [172.16.106.20] ***************************************************************************************
TASK [Gathering Facts] *************************************************************************************
ok: [172.16.106.20]
TASK [hello world] *****************************************************************************************
changed: [172.16.106.20]
PLAY RECAP *************************************************************************************************
172.16.106.20 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
demo 2: Specify user groups
The default is /etc/ansible/hosts Inside
- see
cat /etc/ansible/hosts
# Output
[web]
172.16.106.20 ansible_ssh_user='ubuntu20'
172.16.106.21 ansible_ssh_user='ubuntu20'
172.16.106.22 ansible_ssh_user='ubuntu20'
- edit
sudo nano demo2.yaml
# Revised as follows
- hosts: web # Designated host
remote_user: ubuntu20 # Specifies the user who performs tasks on the managed host
tasks: # Task list ↓
- name: hello world # Task name close firewall
command: 'echo hello world' # call command modular Execute the turn off firewall command
- perform
ansible-playbook demo2.yml --syntax-check
ansible-playbook demo2.yaml
- Output is as follows
PLAY [web] *********************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************
ok: [172.16.106.20]
ok: [172.16.106.21]
ok: [172.16.106.22]
TASK [hello world] *************************************************************************************************************************
changed: [172.16.106.20]
changed: [172.16.106.21]
changed: [172.16.106.22]
PLAY RECAP *********************************************************************************************************************************
172.16.106.20 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
172.16.106.21 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
172.16.106.22 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
demo 3: Approximate folder structure
tree
# Output is as follows
.
├── demo3.yaml
└── hosts
└── demo3.ini
- edit hosts Folder
sudo nano hosts/demo3.ini
# Revised as follows :
[web]
172.16.106.20 ansible_ssh_user='ubuntu20'
172.16.106.21 ansible_ssh_user='ubuntu20'
172.16.106.22 ansible_ssh_user='ubuntu20'
- edit yaml file
sudo nano demo3.yaml
# Revised as follows :
- hosts: web
tasks:
- name: echo hello world
command: 'echo hello world'
- function
ansible-playbook demo3.yaml --syntax-check
ansible-playbook -i hosts/demo3.ini demo3.yaml
demo 4: add to roles Folder
# undetermined Write it yourself
other
If there is any omission, please add
If you have any questions, please leave a message
If it works, please like it
边栏推荐
- Adaptive Bezier curve network for real-time end-to-end text recognition
- MySQL19-Linux下MySQL的安装与使用
- windows无法启动MYSQL服务(位于本地计算机)错误1067进程意外终止
- MySQL25-索引的创建与设计原则
- Postman uses scripts to modify the values of environment variables
- Navicat 導出錶生成PDM文件
- Bytetrack: multi object tracking by associating every detection box paper reading notes ()
- MySQL35-主从复制
- 数据库中间件_Mycat总结
- Copy constructor template and copy assignment operator template
猜你喜欢

MySQL35-主从复制

Windows cannot start the MySQL service (located on the local computer) error 1067 the process terminated unexpectedly

Postman uses scripts to modify the values of environment variables

MySQL 29 other database tuning strategies

Installation and use of MySQL under MySQL 19 Linux

CSDN问答标签技能树(五) —— 云原生技能树

A trip to Macao - > see the world from a non line city to Macao

API learning of OpenGL (2002) smooth flat of glsl

MySQL34-其他数据库日志

保姆级手把手教你用C语言写三子棋
随机推荐
CSDN问答模块标题推荐任务(一) —— 基本框架的搭建
MySQL25-索引的创建与设计原则
MySQL22-逻辑架构
Mysql35 master slave replication
CSDN问答标签技能树(五) —— 云原生技能树
MySQL30-事务基础知识
Water and rain condition monitoring reservoir water and rain condition online monitoring
How to find the number of daffodils with simple and rough methods in C language
MySQL 20 MySQL data directory
SSM整合笔记通俗易懂版
MySQL34-其他数据库日志
[reading notes] rewards efficient and privacy preserving federated deep learning
Swagger、Yapi接口管理服务_SE
February 13, 2022 - Maximum subarray and
The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
Just remember Balabala
【博主推荐】C#生成好看的二维码(附源码)
[paper reading notes] - cryptographic analysis of short RSA secret exponents
MySQL24-索引的数据结构
Time in TCP state_ The role of wait?