我有大约50个Debian Linux服务器,其中有一个糟糕的cron作业:
0 * * * * ntpdate 10.20.0.1
Run Code Online (Sandbox Code Playgroud)
我想用ntpd配置ntp sync,所以我需要删除这个cron作业.对于配置我使用Ansible.我试图用这个游戏删除cron条目:
tasks:
- cron: name="ntpdate" minute="0" job="ntpdate 10.20.0.1" state=absent user="root"
Run Code Online (Sandbox Code Playgroud)
没啥事儿.
然后我运行这个游戏:
tasks:
- cron: name="ntpdate" minute="0" job="ntpdate pool.ntp.org" state=present
Run Code Online (Sandbox Code Playgroud)
我在"crontab -l"的输出中看到新的cron作业:
...
# m h dom mon dow command
0 * * * * ntpdate 10.20.0.1
#Ansible: ntpdate
0 * * * * ntpdate pool.ntp.org
Run Code Online (Sandbox Code Playgroud)
但是/etc/cron.d
空的!我不明白Ansible cron模块是如何工作的.
如何使用Ansible的cron模块删除我手动配置的cron作业?
Ansible Best Practices描述了每个角色都包含具有此规则所需的所有文件的文件目录.
在我的情况下,我有不同的角色,共享相同的文件.但我不能在每个角色中复制这些文件,因为这些文件没有任何一个来源,如果其中一个文件发生编辑,对每个角色进行此更改将变得很繁琐.
我做的一个解决方案是创建另一个文件夹并使用绝对或相对路径引用它.这是最好的方式吗?
我的ansible目录看起来像这样
play.yml
roles/
web/
tasks/
files/
common-1
common-2
other-multiple-files
role-2/
tasks/
files/
common-1
common-2
other-multiple-files
role-3/
tasks/
files/
common-2
role-4/
tasks/
files/
common-1
Run Code Online (Sandbox Code Playgroud) 我正在使用Terraform在AWS中创建一些服务.其中一项服务是ECS任务定义.我按照文档操作,并不断收到以下错误:
aws_ecs_task_definition.github-backup: ClientException: Fargate requires task definition to have execution role ARN to support ECR images.
status code: 400, request id: 84df70ec-94b4-11e8-b116-97f92c6f483f
Run Code Online (Sandbox Code Playgroud)
首先task_role_arn
是可选的,我可以看到创建了一个新角色.我还尝试使用任务定义所需的权限创建一个角色.
这就是我所拥有的:
resource "aws_ecs_task_definition" "github-backup" {
family = "${var.task_name}"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = "${var.fargate_cpu}"
memory = "${var.fargate_memory}"
task_role_arn = "${aws_iam_role.github-role.arn}"
container_definitions = <<DEFINITION
[
{
"cpu": ${var.fargate_cpu},
"image": "${var.image}",
"memory": ${var.fargate_memory},
"name": "github-backup",
"networkMode": "awsvpc"
}
]
DEFINITION
}
Run Code Online (Sandbox Code Playgroud)
resource "aws_iam_policy" "access_policy" {
name = "github_policy"
policy = <<EOF
{ …
Run Code Online (Sandbox Code Playgroud) 我已经看到很多关于如何使用Terraform启动AWS资源的示例.我也看到很多声称Terraform是云不可知的.
我没有看到的是我如何使用单个tf
文件在AWS或Azure中使用某些子网,某些实例,某些ELB以及一些数据库启动VPC的示例.
有没有人有这样的例子?
我知道创建自定义__repr__
或__add__
方法(等等),以修改运算符和函数的行为.是否有方法覆盖len
?
例如:
class Foo:
def __repr__(self):
return "A wild Foo Class in its natural habitat."
foo = Foo()
print(foo) # A wild Foo Class in its natural habitat.
print(repr(foo)) # A wild Foo Class in its natural habitat.
Run Code Online (Sandbox Code Playgroud)
这可以len
用列表来完成吗?通常,它看起来像这样:
foo = []
print(len(foo)) # 0
foo = [1, 2, 3]
print(len(foo)) # 3
Run Code Online (Sandbox Code Playgroud)
如果我想让搜索类型超出计数范围怎么办?像这样:
class Bar(list):
pass
foo = [Bar(), 1, '']
print(len(foo)) # 3
count = 0
for item in foo: …
Run Code Online (Sandbox Code Playgroud) 我想配置只能通过Linux跳转主机访问子网的Windows主机.
Windows机器使用winrm连接方法.Linux跳转服务器可通过SSH获得.
我可以直接使用以下命令访问Windows主机:
ansible_connection: winrm
Run Code Online (Sandbox Code Playgroud)
如果我尝试通过以下方式将任务委派给Linux跳转服务器(可以直接访问Windows):
- name: Ping windows
hosts: windows_machines
tasks:
- name: ping
win_ping:
delegate_to: "{{ item }}"
with_items: "{{ groups['jump_servers'][0] }}"
Run Code Online (Sandbox Code Playgroud)
它尝试连接以建立与跳转主机的WINRM连接.不完全是我的想法.
请注意,对于windows_machines组,我定义了group_vars:
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore
Run Code Online (Sandbox Code Playgroud)
我应该如何通过堡垒主机配置Windows主机?
我认为这是剧本中产生错误的部分.我该如何重写这部分内容?
roles:
- role: json-transform
json_transforms: '{{ clientValidation.json_transforms}}'
Run Code Online (Sandbox Code Playgroud)
它抛出以下警告:
[DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable syntax ('{{json_transforms}}'). This feature will be removed in a
future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
Run Code Online (Sandbox Code Playgroud) 当建立一个新的Linux服务器,我通常跑apt-get update
后apt-get upgrade
.第一个命令更新可用软件包及其版本的列表,但它不会安装或升级任何软件包.第二个命令实际上安装了我的软件包的更新版本.
在Ansible中执行此操作的正确方法是什么?你可以这样做的一种方法是这样的:
- name: update and upgrade apt packages
apt: >
upgrade=yes
update_cache=yes
cache_valid_time=3600
Run Code Online (Sandbox Code Playgroud)
或者你可以分两步完成:
- name: update apt packages
apt: >
update_cache=yes
cache_valid_time=3600
- name: upgrade apt packages
apt: upgrade=yes
Run Code Online (Sandbox Code Playgroud)
如果你是第一种方式,Ansible足够聪明,知道它应该在'升级'之前运行'更新'吗?Ansible apt文档没有解决这个问题.
我正在尝试为MySQL RDS实例创建Route53条目,但是:3306
从Terraform返回的RDS端点末尾有问题.
resource "aws_db_instance" "mydb" {
allocated_storage = 10
engine = "mysql"
engine_version = "5.6.17"
instance_class = "db.t2.micro"
name = "mydb"
username = "foo"
password = "bar"
db_subnet_group_name = "my_database_subnet_group"
parameter_group_name = "default.mysql5.6"
}
resource "aws_route53_record" "database" {
zone_id = "${aws_route53_zone.primary.zone_id}"
name = "database.example.com"
type = "CNAME"
ttl = "300"
records = ["${aws_db_instance.default.endpoint}"]
}
Run Code Online (Sandbox Code Playgroud)
Terraform将a :3306
放在端点的末尾,并将其输入到CNAME的Route53值.
当我尝试database.example.com
使用MySQL客户端连接到CNAME时,我得到:
ERROR 2005 (HY000): Unknown MySQL server host 'database.example.com' (0)
Run Code Online (Sandbox Code Playgroud)
一旦我通过AWS route53控制台删除:3306它似乎工作得很好.
问题是:如何:3306
从Terraform RDS端点剥离
我看到亚马逊推出了从原生MySQL到Amazon Aurora MySQL的新Amazon Aurora MySQL 迁移.
是否可以使用Amazon RDS从Amazon Aurora迁移回常规MySQL?
ansible ×5
terraform ×3
linux ×2
mysql ×2
amazon-ecs ×1
amazon-rds ×1
apt ×1
azure ×1
debian ×1
python ×1
python-3.x ×1
rds ×1