ad hoc ---临时的,在ansible里需要快速执行,并不用保存命令的执行方式

简单命令

playbook 复杂命令

 

 

EXAMPLES:

- name: install the latest version of Apache
yum:
name: httpd
state: latest - name: ensure a list of packages installed
yum:
name: "{{ packages }}"
vars:
packages:
- httpd
- httpd-tools - name: remove the Apache package
yum:
name: httpd
state: absent - name: install the latest version of Apache from the testing repo
yum:
name: httpd
enablerepo: testing
state: present - name: install one specific version of Apache
yum:
name: httpd-2.2.29-1.4.amzn1
state: present - name: upgrade all packages
yum:
name: '*'
state: latest - name: upgrade all packages, excluding kernel & foo related packages
yum:
name: '*'
state: latest
exclude: kernel*,foo* - name: install the nginx rpm from a remote repo
yum:
name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present - name: install nginx rpm from a local file
yum:
name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present - name: install the 'Development tools' package group
yum:
name: "@Development tools"
state: present - name: install the 'Gnome desktop' environment group
yum:
name: "@^gnome-desktop-environment"
state: present - name: List ansible packages and register result to print with debug later.
yum:
list: ansible
register: result - name: Install package with multiple repos enabled
yum:
name: sos
enablerepo: "epel,ol7_latest" - name: Install package with multiple repos disabled
yum:
name: sos
disablerepo: "epel,ol7_latest" - name: Install a list of packages
yum:
name:
- nginx
- postgresql
- postgresql-server
state: present - name: Download the nginx package but do not install it
yum:
name:
- nginx
state: latest
download_only: true
   EXAMPLES: - name: example copying file with owner and permissions
copy:
src: /srv/myfiles/foo.conf
dest: /etc/foo.conf
owner: foo
group: foo
mode: 0644 - name: The same example as above, but using a symbolic mode equivalent to 0644
copy:
src: /srv/myfiles/foo.conf
dest: /etc/foo.conf
owner: foo
group: foo
mode: u=rw,g=r,o=r - name: Another symbolic mode example, adding some permissions and removing others
copy:
src: /srv/myfiles/foo.conf
dest: /etc/foo.conf
owner: foo
group: foo
mode: u+rw,g-wx,o-rwx - name: Copy a new "ntp.conf file into place, backing up the original if it differs from the copied version
copy:
src: /mine/ntp.conf
dest: /etc/ntp.conf
owner: root
group: root
mode: 0644
backup: yes - name: Copy a new "sudoers" file into place, after passing validation with visudo
copy:
src: /mine/sudoers
dest: /etc/sudoers
validate: /usr/sbin/visudo -cf %s - name: Copy a "sudoers" file on the remote machine for editing
copy:
src: /etc/sudoers
dest: /etc/sudoers.edit
remote_src: yes
validate: /usr/sbin/visudo -cf %s - name: Copy using the 'content' for inline data
copy:
content: '# This file was moved to /etc/other.conf'
dest: /etc/mine.conf' RETURN VALUES: dest:
description: destination file/path
returned: success
type: string
sample: /path/to/file.txt
src:
description: source file used for the copy on the target machine
returned: changed
type: string
sample: /home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source
md5sum:
description: md5 checksum of the file after running copy
returned: when supported
type: string
sample: 2a5aeecc61dc98c4d780b14b330e3282
checksum:
description: sha1 checksum of the file after running copy
returned: success
type: string
sample: 6e642bb8dd5c2e027bf21dd923337cbb4214f827
backup_file:
description: name of backup file created
returned: changed and if backup=yes
type: string
sample: /path/to/file.txt.2015-02-12@22:09~
gid:
description: group id of the file, after execution
returned: success
type: int
sample: 100
group:
description: group of the file, after execution
returned: success
type: string
sample: httpd
owner:
description: owner of the file, after execution
returned: success
type: string
sample: httpd
uid:
description: owner id of the file, after execution
returned: success
type: int
sample: 100
mode:
description: permissions of the target, after execution
returned: success
type: string
sample: 0644
size:
description: size of the target, after execution
returned: success
type: int
sample: 1220
state:
description: state of the target, after execution
returned: success
type: string
sample: file

 

EXAMPLES:

- name: Add the user 'johnd' with a specific uid and a primary group of 'admin'
user:
name: johnd
comment: John Doe
uid: 1040
group: admin - name: Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups
user:
name: james
shell: /bin/bash
groups: admins,developers
append: yes - name: Remove the user 'johnd'
user:
name: johnd
state: absent
remove: yes - name: Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa
user:
name: jsmith
generate_ssh_key: yes
ssh_key_bits: 2048
ssh_key_file: .ssh/id_rsa - name: Added a consultant whose account you want to expire
user:
name: james18
shell: /bin/zsh
groups: developers
expires: 1422403387 - name: starting at version 2.6, modify user, remove expiry time
user:
name: james18
expires: -1 RETURN VALUES: append:
description: Whether or not to append the user to groups
returned: When state is 'present' and the user exists
type: bool
sample: True
comment:
description: Comment section from passwd file, usually the user name
returned: When user exists
type: string
sample: Agent Smith
create_home:
description: Whether or not to create the home directory
returned: When user does not exist and not check mode
type: bool
sample: True
force:
description: Whether or not a user account was forcibly deleted
returned: When state is 'absent' and user exists
type: bool
sample: False
group:
description: Primary user group ID
returned: When user exists
type: int
sample: 1001
groups:
description: List of groups of which the user is a member
returned: When C(groups) is not empty and C(state) is 'present'
type: string
sample: 'chrony,apache'
home:
description: "Path to user's home directory"
returned: When C(state) is 'present'
type: string
sample: '/home/asmith'
move_home:
description: Whether or not to move an existing home directory
returned: When C(state) is 'present' and user exists
type: bool
sample: False
name:
description: User account name
returned: always
type: string
sample: asmith
password:
description: Masked value of the password
returned: When C(state) is 'present' and C(password) is not empty
type: string
sample: 'NOT_LOGGING_PASSWORD'
remove:
description: Whether or not to remove the user account
returned: When C(state) is 'absent' and user exists
type: bool
sample: True
shell:
description: User login shell
returned: When C(state) is 'present'
type: string
sample: '/bin/bash'
ssh_fingerprint:
description: Fingerprint of generated SSH key
returned: When C(generate_ssh_key) is C(True)
type: string
sample: '2048 SHA256:aYNHYcyVm87Igh0IMEDMbvW0QDlRQfE0aJugp684ko8 ansible-generated on host (RSA)'
ssh_key_file:
description: Path to generated SSH public key file
returned: When C(generate_ssh_key) is C(True)
type: string
sample: /home/asmith/.ssh/id_rsa
ssh_public_key:
description: Generated SSH public key file
returned: When C(generate_ssh_key) is C(True)
type: string
sample: >
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC95opt4SPEC06tOYsJQJIuN23BbLMGmYo8ysVZQc4h2DZE9ugbjWWGS1/pweUGjVstgzMkBEeBCB
618mUJBvdlEgea96QGjOwSB7/gmonduC7gsWDMNcOdSE3wJMTim4lddiBx4RgC9yXsJ6Tkz9BHD73MXPpT5ETnse+A3fw3IGVSjaueVnlUyUmOBf7fz
d5u1u0e6Acju/8aZ/l17IDFiLke5IzlqIMRTEbDwLNeO84YQKWTm9fODHzhYe0yvxqLiK07 ansible-generated on host'
stderr:
description: Standard error from running commands
returned: When stderr is returned by a command that is run
type: string
sample: Group wheels does not exist
stdout:
description: Standard output from running commands
returned: When standard output is returned by the command that is run
type: string
sample:
system:
description: Whether or not the account is a system account
returned: When C(system) is passed to the module and the account does not exist
type: bool
sample: True
uid:
description: User ID of the user account
returned: When C(UID) is passed to the module
type: int
sample: 1044

 

[root@ftp:/root]
> ansible webservers -m shell -a 'uptime' -o
ansible03 | CHANGED | rc=0 | (stdout) 17:34:22 up 4:12, 2 users, load average: 0.00, 0.01, 0.05
ansible04 | CHANGED | rc=0 | (stdout) 17:34:22 up 3:45, 2 users, load average: 0.16, 0.05, 0.05
ansible02 | CHANGED | rc=0 | (stdout) 17:34:22 up 3:41, 1 user, load average: 0.00, 0.01, 0.05
ansible01 | CHANGED | rc=0 | (stdout) 17:34:22 up 4:11, 2 users, load average: 0.00, 0.01, 0.05 [root@ftp:/root]
> ansible webservers -m shell -a 'uptime' -o -f 10
ansible03 | CHANGED | rc=0 | (stdout) 17:34:56 up 4:12, 2 users, load average: 0.00, 0.01, 0.05
ansible01 | CHANGED | rc=0 | (stdout) 17:34:56 up 4:12, 2 users, load average: 0.24, 0.06, 0.06
ansible04 | CHANGED | rc=0 | (stdout) 17:34:56 up 3:45, 2 users, load average: 0.10, 0.04, 0.05
ansible02 | CHANGED | rc=0 | (stdout) 17:34:56 up 3:41, 1 user, load average: 0.00, 0.01, 0.05 [root@ftp:/root]
>

 

[root@ftp:/root]
> ansible webservers -m copy -a 'src=/etc/hosts dest=/tmp/hosts owner=root group=root mode=777'
ansible04 | CHANGED => {
"changed": true,
"checksum": "19aad245261f1772bffdabf3a6f5347312b20b46",
"dest": "/tmp/hosts",
"gid": 0,
"group": "root",
"md5sum": "39c0b18a971b35e3888758a2494b6083",
"mode": "0777",
"owner": "root",
"size": 346,
"src": "/root/.ansible/tmp/ansible-tmp-1552815757.85-214840644098444/source",
"state": "file",
"uid": 0
}
ansible03 | CHANGED => {
"changed": true,
"checksum": "19aad245261f1772bffdabf3a6f5347312b20b46",
"dest": "/tmp/hosts",
"gid": 0,
"group": "root",
"md5sum": "39c0b18a971b35e3888758a2494b6083",
"mode": "0777",
"owner": "root",
"size": 346,
"src": "/root/.ansible/tmp/ansible-tmp-1552815757.82-188384435660718/source",
"state": "file",
"uid": 0
}
ansible01 | CHANGED => {
"changed": true,
"checksum": "19aad245261f1772bffdabf3a6f5347312b20b46",
"dest": "/tmp/hosts",
"gid": 0,
"group": "root",
"md5sum": "39c0b18a971b35e3888758a2494b6083",
"mode": "0777",
"owner": "root",
"size": 346,
"src": "/root/.ansible/tmp/ansible-tmp-1552815757.71-273021490189009/source",
"state": "file",
"uid": 0
}
ansible02 | CHANGED => {
"changed": true,
"checksum": "19aad245261f1772bffdabf3a6f5347312b20b46",
"dest": "/tmp/hosts",
"gid": 0,
"group": "root",
"md5sum": "39c0b18a971b35e3888758a2494b6083",
"mode": "0777",
"owner": "root",
"size": 346,
"src": "/root/.ansible/tmp/ansible-tmp-1552815757.77-7921352044895/source",
"state": "file",
"uid": 0
} [root@ftp:/root]
>

 

ansible组件 Ad-Hoc的更多相关文章

  1. SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问

    delphi ado 跨数据库访问 语句如下 ' and db = '帐套1' 报错内容是:SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATE ...

  2. SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问

    消息 15281,级别 16,状态 1,第 2 行SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/Open ...

  3. Sql导出数据报错-->SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问

    SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服 ...

  4. 解除SQL对组件"Ad Hoc Distributed Queries"的"STATEMENT'OpenRowset OpenDatasource"的访问

      SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为 ...

  5. SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。

    今天单位一ASP.NET网站,里面有个功能是导出数据,发现一导出就报错,报错内容是:SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT ...

  6. [原创]SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问

    TSQL查询Excel数据使用openrowset通常会报如下错误: 消息 ,级别 ,状态 ,第 行 SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 ...

  7. 关于“SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问 ”

    原因:在从远程服务器复制数据到本地时出现“SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatas ...

  8. SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问的解决方案

    今天写了一个excel表的导入功能,结果在excel表中的内容导入到页面时报错:SQL  Server 阻止了对组件 'Ad Hoc Distributed Queries' 的  STATEMENT ...

  9. 解决SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问

    根据需要进行asp.net的数据导入导出,结果报以下错: mark-1: [报错]SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT ...

  10. [sql异常]SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的

    //执行远程数据库表查询 SELECT * FROM OPENDATASOURCE('SQLOLEDB', 'Data Source=数据库地址;User ID=sa;password=sa' ).n ...

随机推荐

  1. [USACO17JAN] Promotion Counting晋升者计数 (树状数组+dfs)

    题目大意:给你一棵树,求以某节点为根的子树中,权值大于该节点权值的节点数 本题考查dfs的性质 离散+树状数组求逆序对 先离散 我们发现,求逆序对时,某节点的兄弟节点会干扰答案 所以,我们在递推时统计 ...

  2. [CodeForces]786B Legacy

    线段树优化建图. 建立两棵线段树,其上点的点权分别表示"到达这个区间内所有点的最小花费"和"到达这个区间内任意一个点的最小花费". 对于第一种路直接加边即可 对 ...

  3. Problem 6

    Problem 6 # Problem_6.py """ The sum of the squares of the first ten natural numbers ...

  4. [剑指offer] 29. 顺时针打印矩阵 (for循环条件)

    思路: 先定义左上和右下角点坐标,打印可分为从左到右,从上到下,从右到左,从下到上.依次判断最后一圈的四个循环条件. #include "../stdafx.h" #include ...

  5. NOIP2018提高组金牌训练营——动态规划专题

    NOIP2018提高组金牌训练营——动态规划专题 https://www.51nod.com/Live/LiveDescription.html#!#liveId=19 多重背包 二进制优化转化成01 ...

  6. 【ACM-ICPC 2018 南京赛区网络预赛 E】AC Challenge

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个DP 设f[j]表示已经做的题的状态为j的情况下接着选能获得的最大分数. 显然是个倒推. 记忆化搜索一波 dfs(i,j) 表示 ...

  7. 【codeforces 723F】st-Spanning Tree

    [题目链接]:http://codeforces.com/contest/723/problem/F [题意] 给你一张图; 让你选择n-1条边; 使得这张图成为一颗树(生成树); 同时s的度数不超过 ...

  8. 使用joomla通过CSV文件上传数据存入数据库并使用JavaScript验证码是否符合规则

    1,实现效果截图 2,A.php上传CSV文件表单 2-1:html结构使用jqeury.form.min.js表单框架异步提交 <div class="uploadFile bord ...

  9. 设置utf8编码问题

    注意:乱码和request的具体实现类有关,现在已经查到的是RequestDispatcher.forward调用前使用的是org.apache.catalina.connector.RequestF ...

  10. 路由器一键桥接Android实现

    開始之前,首先说一下什么叫一键桥接,所谓一键桥接,就是点击一下.就能够对所连接的路由器进行网络中继设置.以实现路由器能够通过已有的无线路由器进行网络訪问. 那么实现这个功能有几种方法呢?能够说有非常多 ...