Bảng cheat Ansible pdf

Câu hỏi thường gặp

Chỉ hiển thị nội dung serverplaybook

Show

cấu hình-cm $servername

Làm cách nào để thêm vai trò?

configure-cm --role $role $servername

Xóa một vai trò?

configure-cm --delete --role $role $server --message "$reason"

Thêm một kế hoạch chi tiết?

cấu hình-cm -b $blueprint $servername

Xóa bản thiết kế?

configure-cm --delete --blueprint $blueprint $server

Hiển thị tài liệu về mô-đun Ansible

ansible-doc $modulename

Thêm biến playbook?

configure-cm --var múi giờ=UTC degtlun7904

Thêm biến playbook?

configure-cm --var '[{ntp_servers. [145. 228. 39. 44,145. 228. 145. 3]}]' degtlun7904

Thêm biến playbook?

configure-cm --var @/tmp/yaml_file degtlun7904

Làm cách nào để khắc phục các thay đổi trong playbook không được cam kết?

configure-cm --commit-only $servername

Thêm một biến có vai trò

configure-cm --role postfix --var relayhost=cmail. xuyên mạng. net $srvname

 

thêm sudoer

cấu hình-cm $servername --sudoers TOMCAT_sudoers

Thêm Tác vụ từ tệp YAML - Giới hạn người dùng

$ cat /tmp/ansible_task.yml
---
- name: degtlun7904.yml | /etc/security/limits.conf | Set user limits nofile
  pam_limits:
    domain: '*'
    limit_type: "-"
    limit_item: "nofile"
    value: 8192
  tags: limits

$ configure-cm degtlun7904 --task /tmp/ansible_task.yml
$ run-cm degtlun7904 -t limits

thêm một gói

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs

Thêm một nhóm mạng

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups

 

Công cụ trên degtlun1235

chạy cm

Chạy playbook Ansible

cấu hình-cm

Định cấu hình playbook máy chủ

phân phối_jumpserver. sh

Cập nhật vai trò máy chủ nhảy trên tất cả các máy chủ nhảy

vai trò

asmlib

apache

ngao

CỐT LÕI

đồng bộ hóa

csrepo

cốc

người đóng tàu

bổ sung_repo

nfs_mount

nfs_server

hậu tố

sdk_repo

symantec

symantec_hids

bản thiết kế

apache

check_mk

đầu bếp

cs_nrpe_client

ggaddm

hana

mysql

ORA

postgres

nhựa cây

SYB

WEB

CORE - Các thẻ biến quan trọng

dns_search

dns_search. như. lekkerland. com otg. tập đoàn. máy chủ int. hệ thống arvato. de betelsmann. de

dns

dns_servers

dns_servers.
- 172. 25. 192. 31
- 172. 25. 192. 20
- 172. 25. 168. 12

dns

dns_no_shuffle

dns_no_shuffle. ĐÚNG VẬY

dns

kernel_ip_forwarding

kernel_ip_forwarding. 1

chuyển tiếp ip

pe_numbers

pe_numbers.
- số. PE00001111
   lý do. FTP
   ngày kết thúc. 20170616

motd

sshd_only_dialogip

sshd_only_dialogip. ĐÚNG VẬY

sshd

Múi giờ

Múi giờ. UTC

Múi giờ

a

Một thẻ đã tồn tại với tên chi nhánh được cung cấp. Nhiều lệnh Git chấp nhận cả tên thẻ và tên nhánh, vì vậy việc tạo nhánh này có thể gây ra hành vi không mong muốn. Bạn có chắc chắn muốn tạo nhánh này không?

thực thi với phiên bản python từ xa cụ thể, python từ xa, viết lại biến mặc định, viết lại biến, ghi đè biến

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"

chỉ thực thi ansible cho một máy chủ, một máy chủ, một máy chủ xóa, mức độ chi tiết

pip3 install ansible 
# for python2 - default installation 
pip install ansible
0

tập tin đơn giản để tạo một thư mục

pip3 install ansible 
# for python2 - default installation 
pip install ansible
1

thực thi ansible cục bộ, thực thi cục bộ

pip3 install ansible 
# for python2 - default installation 
pip install ansible
2

thực thi ansible-playbook với tham số bên ngoài, tập lệnh bash ansible-playbook với tham số, biến phụ, biến ngoài, env var

pip3 install ansible 
# for python2 - default installation 
pip install ansible
3

pip3 install ansible 
# for python2 - default installation 
pip install ansible
4

với đường dẫn đến tệp cho các tham số bên ngoài, các biến bổ sung từ tệp bên ngoài

pip3 install ansible 
# for python2 - default installation 
pip install ansible
5

biến bên ngoài nội tuyến

pip3 install ansible 
# for python2 - default installation 
pip install ansible
6

kiểm tra xem nó có hoạt động không, lệnh ad-hoc

pip3 install ansible 
# for python2 - default installation 
pip install ansible
7

pip3 install ansible 
# for python2 - default installation 
pip install ansible
8

ví dụ vòng lặp

pip3 install ansible 
# for python2 - default installation 
pip install ansible
9

thực hiện lặp lại

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
40

bắt đầu với nhiệm vụ, thực hiện từ nhiệm vụ, bắt đầu với nhiệm vụ, bỏ qua các nhiệm vụ trước đó

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
41

thay thế các biến bên trong tệp thành tệp chuyên dụng, di chuyển vars sang tệp riêng

  • trước

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
42

  • sau (khối 'vars' trống) filepath

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
43

hoặc groupvars

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
44

mã số

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
45

di chuyển mã vào tệp riêng biệt, tác vụ vào tệp

cắt mã từ tệp gốc và dán vào tệp riêng (có căn chỉnh phù hợp. ), viết thay vì mã

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
46

tập tin thích hợp nên được tạo ra

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
47

bỏ qua/kích hoạt một số tác vụ với ghi nhãn, gắn thẻ

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
48

đa thẻ, nhiều thẻ

# Tabcompletion for packages from csrepo
$ configure-cm $servername --pkg dba-tomcat-7047-core
$ run-cm $servername -t pkgs
49

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
40

gỡ lỗi

cẩm nang sửa lỗi

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
41

biến in

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
42

thay đổi biến

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
43

đặt biến

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
44

vỏ == ansible. được xây dựng trong. vỏ bọc

quản lý chơi

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
45

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
46

lệnh gỡ lỗi

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
47

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
48

biến env bashrc

# Tabcompletion
$ configure-cm $srvname --netgroup ng_dba_ext
$ run-cm $srvname -t netgroups
49

sao chép tập tin rsync

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
40

ec2 quản lý luồng không khí ec2

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
41

mô-đun gỡ lỗi

tệp đối số ( args. json )

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
42

tập tin thực thi

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
43

đặt điểm dừng

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
44

chạy cho đến khi điểm dừng

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
45

gỡ lỗi mô-đun nội tuyến, thực thi mô-đun nội tuyến, kiểm tra mô-đun adhoc

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
46

nhiệm vụ in tất cả các biến

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
47

ansible-console

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
48

thiết bị xuất chuẩn in ansible

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
49

xử lý lỗi, thử bắt

ngừng thực hiện các bước (của playbook) khi có ít nhất một máy chủ báo lỗi

pip3 install ansible 
# for python2 - default installation 
pip install ansible
40

không ném lỗi cho một nhiệm vụ nhất định

pip3 install ansible 
# for python2 - default installation 
pip install ansible
41

thất bại khi, thất bại theo điều kiện, phân tích tệp nhật ký để tìm lỗi

pip3 install ansible 
# for python2 - default installation 
pip install ansible
42

mẫu, tạo khuôn mẫu Jinja2, đường ống, lọc ansible

giá trị mặc định

pip3 install ansible 
# for python2 - default installation 
pip install ansible
43

thoát ký tự đặc biệt

pip3 install ansible 
# for python2 - default installation 
pip install ansible
44

hoạt động với danh sách

pip3 install ansible 
# for python2 - default installation 
pip install ansible
45

tên tệp từ đường dẫn (trả về 'script. ch')

pip3 install ansible 
# for python2 - default installation 
pip install ansible
46

sao chép tập tin và đổi tên nó, hậu tố thay thế đường ống

pip3 install ansible 
# for python2 - default installation 
pip install ansible
47

điều kiện jinja

pip3 install ansible 
# for python2 - default installation 
pip install ansible
48

sao chép sao chép ngược từ máy đích

pip3 install ansible 
# for python2 - default installation 
pip install ansible
49

chỉ thị cho Jinja

để cải thiện thụt đầu dòng trên toàn cầu trong tệp, hãy thêm một trong những dòng tiếp theo vào đầu

pip3 install ansible 
# for python2 - default installation 
pip install ansible
40

chỉ để cải thiện thụt đầu dòng cho khối

pip3 install ansible 
# for python2 - default installation 
pip install ansible
41

ví dụ điều kiện

pip3 install ansible 
# for python2 - default installation 
pip install ansible
42

chỉ thị cho vòng lặp, vòng lặp cuối cùng, vòng lặp cuối cùng

pip3 install ansible 
# for python2 - default installation 
pip install ansible
43

trốn thoát

chỉ là một biểu tượng

pip3 install ansible 
# for python2 - default installation 
pip install ansible
44

đoạn mã lớn hơn

pip3 install ansible 
# for python2 - default installation 
pip install ansible
45

mẫu với tempfile

pip3 install ansible 
# for python2 - default installation 
pip install ansible
46

mô-đun
  • tạo mô-đun tùy chỉnh

cài đặt cho các mô-đun

cũng cần 'thông báo' ansible về mô-đun đưa ra một trong các tùy chọn tiếp theo

  • thêm thư mục của bạn với mô-đun vào biến môi trường ANSIBLE_LIBRARY
  • cập nhật $HOME/. ansible. cfg

    pip3 install ansible 
    # for python2 - default installation 
    pip install ansible
    47

tài liệu mô-đun

pip3 install ansible 
# for python2 - default installation 
pip install ansible
48

mô-đun tối thiểu

pip3 install ansible 
# for python2 - default installation 
pip install ansible
49

bổ sung

ví dụ về plugin

pip3 install ansible 
# for python2 - default installation 
pip install ansible
40

mã python cho plugin

pip3 install ansible 
# for python2 - default installation 
pip install ansible
41

chấp hành

pip3 install ansible 
# for python2 - default installation 
pip install ansible
42

tra cứu

pip3 install ansible 
# for python2 - default installation 
pip install ansible
43

thay thế giá trị từ tệp có định dạng đặc biệt

pip3 install ansible 
# for python2 - default installation 
pip install ansible
44

biến tra cứu

pip3 install ansible 
# for python2 - default installation 
pip install ansible
45

pip3 install ansible 
# for python2 - default installation 
pip install ansible
46

tập tin kiểm kê

tệp kiểm kê, tệp kiểm kê có biến, quy tắc

pip3 install ansible 
# for python2 - default installation 
pip install ansible
47

hàng tồn kho động

hàng tồn kho trăn. py (có phần mở rộng 'py') thay vì txt

pip3 install ansible 
# for python2 - default installation 
pip install ansible
48

logic tiếp theo cũng nên có mặt

pip3 install ansible 
# for python2 - default installation 
pip install ansible
49

kịch bản chuẩn bị

tệp kiểm kê với các biến ( python Jinja tạo khuôn mẫu)

pip3 install ansible 
# for python2 - default installation 
pip install ansible
40

cách sử dụng sách giải trí

pip3 install ansible 
# for python2 - default installation 
pip install ansible
41

thực hiện với các ví dụ về khoảng không quảng cáo

cho một máy chủ cụ thể không có tệp kiểm kê

pip3 install ansible 
# for python2 - default installation 
pip install ansible
42

với tập tin hàng tồn kho

pip3 install ansible 
# for python2 - default installation 
pip install ansible
43

vấn đề với playbook thực thi chỉ dành cho máy chủ cục bộ, thực thi cục bộ

pip3 install ansible 
# for python2 - default installation 
pip install ansible
44

dung dịch

pip3 install ansible 
# for python2 - default installation 
pip install ansible
45

giải pháp2

pip3 install ansible 
# for python2 - default installation 
pip install ansible
46

chiến lược

pip3 install ansible 
# for python2 - default installation 
pip install ansible
47

  • tuyến tính (mặc định) sau mỗi bước chờ tất cả các máy chủ
  • miễn phí độc lập cho tất cả các máy chủ - ai đó có thể hoàn tất cài đặt sớm hơn đáng kể so với những người khác

tham số bổ sung - chỉ định số lượng máy chủ sẽ được thực thi tại thời điểm đó (chỉ dành cho chiến lược mặc định)

pip3 install ansible 
# for python2 - default installation 
pip install ansible
48

pip3 install ansible 
# for python2 - default installation 
pip install ansible
49

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
0

giá trị mặc định "nối tiếp" vào cấu hình ansible. cfg

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
1

thực thi không đồng bộ, nhiệm vụ hiện tại, thực thi lệnh

không phải tất cả các mô-đun đều hỗ trợ thao tác này thực thi lệnh ở chế độ không đồng bộ (với ước tính sơ bộ là 120 giây), với kết quả thăm dò mặc định của lệnh - 10 (giây)

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
2

thực thi lệnh ở chế độ không đồng bộ (với ước tính sơ bộ 120 giây), với kết quả thăm dò của lệnh - 60 (giây)

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
3

thực hiện lệnh và quên, không chờ thực hiện

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
4

thực thi lệnh ở chế độ không đồng bộ, ghi kết quả kiểm tra kết quả ở cuối tệp

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
5

vai trò

init project ansible-galaxy, tạo vai trò mới, vai trò init

thực thi mã vào thư mục dự án của bạn '. /vai trò'

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
6

kết quả

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
7

chèn vào mã

--extra-vars "remote_folder=$REMOTE_FOLDER ansible_python_interpreter=/usr/bin/python"
8

tất cả các thư mục của dự án đã tạo sẽ được áp dụng cho dự án của bạn (tác vụ, vars, mặc định) trong trường hợp tạo thủ công - chỉ có thể tạo các thư mục cần thiết

Các thuật ngữ cơ bản được sử dụng trong Ansible là gì?

Điều khoản Ansible .
Người phục vụ. Một thực thể cung cấp dịch vụ cho Ansible của chúng tôi
Cỗ máy. Máy vật lý, máy ảo hoặc vùng chứa
máy mục tiêu. Một máy cuối được cấu hình bởi Ansible
Nhiệm vụ. Một hành động
vở kịch. Một vị trí nơi các tệp YAML được ghi và thực thi

Lệnh Ansible là gì?

Mô-đun lệnh .
lệnh - Thực thi lệnh trên một nút từ xa
mong đợi - Thực hiện lệnh và trả lời lời nhắc
raw - Thực thi lệnh SSH thấp và bẩn
tập lệnh - Chạy tập lệnh cục bộ trên nút từ xa sau khi truyền tập lệnh
shell - Thực thi các lệnh trong các nút
telnet - Thực thi lệnh telnet thấp và bẩn

Có bao nhiêu mô-đun trong Ansible?

12 Các mô-đun Ansible hữu ích và phổ biến .

Kiến trúc Ansible là gì?

Ansible là công cụ tự động hóa CNTT cực kỳ đơn giản giúp tự động hóa việc cung cấp đám mây, quản lý cấu hình, triển khai ứng dụng, điều phối nội bộ dịch vụ và nhiều nhu cầu CNTT khác.