当前位置:网站首页>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
边栏推荐
- MySQL19-Linux下MySQL的安装与使用
- How to change php INI file supports PDO abstraction layer
- 第一篇博客
- MySQL transaction log
- Mysql21 user and permission management
- [BMZCTF-pwn] 12-csaw-ctf-2016-quals hungman
- [paper reading notes] - cryptographic analysis of short RSA secret exponents
- Mysql36 database backup and recovery
- Database middleware_ MYCAT summary
- Use of dataset of pytorch
猜你喜欢

Mysql27 - Optimisation des index et des requêtes

Nanny hand-in-hand teaches you to write Gobang in C language

CSDN-NLP:基于技能树和弱监督学习的博文难度等级分类 (一)

Mysql22 logical architecture
![[C language] deeply analyze the underlying principle of data storage](/img/d6/1c0cd38c75da0d0cc1df7f36938cfb.png)
[C language] deeply analyze the underlying principle of data storage

MySQL21-用戶與權限管理

MySQL32-锁

MySQL27-索引優化與查詢優化

Bytetrack: multi object tracking by associating every detection box paper reading notes ()

Case identification based on pytoch pulmonary infection (using RESNET network structure)
随机推荐
Advantages and disadvantages of evaluation methods
CSDN Q & a tag skill tree (V) -- cloud native skill tree
C language advanced pointer Full Version (array pointer, pointer array discrimination, function pointer)
C language string function summary
API learning of OpenGL (2002) smooth flat of glsl
[paper reading notes] - cryptographic analysis of short RSA secret exponents
API learning of OpenGL (2004) gl_ TEXTURE_ MIN_ FILTER GL_ TEXTURE_ MAG_ FILTER
Time in TCP state_ The role of wait?
Mysql26 use of performance analysis tools
Global and Chinese market for intravenous catheter sets and accessories 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of operational amplifier 2022-2028: Research Report on technology, participants, trends, market size and share
[BMZCTF-pwn] 11-pwn111111
Swagger、Yapi接口管理服务_SE
CSDN question and answer tag skill tree (II) -- effect optimization
[Li Kou 387] the first unique character in the string
【博主推荐】C#生成好看的二维码(附源码)
Mysql28 database design specification
CSDN问答标签技能树(一) —— 基本框架的构建
Global and Chinese market of wafer processing robots 2022-2028: Research Report on technology, participants, trends, market size and share
CSDN markdown editor