我对Ansible很新.我正在尝试遵循Ansible中角色概念的教程.我有以下主手册:
--- # Master Playbook for Webservers
- hosts: apacheweb
user: test
sudo: yes
connection: ssh
roles:
- webservers
Run Code Online (Sandbox Code Playgroud)
这是指具有以下任务/ main.yml的Web服务器角色:
- name: Install Apache Web Server
yum: pkg=httpd state=latest
notify: Restart HTTPD
Run Code Online (Sandbox Code Playgroud)
还有一个handler/main.yml:
- name: Restart HTTPD
service: name=httpd state=started
Run Code Online (Sandbox Code Playgroud)
当我执行上面提到的Master Playbook时,我收到以下错误:
TASK [webservers : Install Apache Web Server] **********************************
fatal: [test.server.com]: FAILED! => {"changed": false, "failed": true, "msg": "The following packages have pending transactions: httpd-x86_64", "rc": 128, "results": ["The following packages have …Run Code Online (Sandbox Code Playgroud) 我想ZonedDateTime在解析数组列表的元素后将它们转换为对象。下面显示了一个字符串。
"2017-02-12 06:59:00 +1300"
Run Code Online (Sandbox Code Playgroud)
目前我使用DateTimeFormatter:
DateTimeFormatter dateTimeFormatter =
DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss ZZ");
Run Code Online (Sandbox Code Playgroud)
并尝试使用parse, 来获取时间:
this.actionTime = dateTimeFormatter.parse(actionTime, ZonedDateTime::from);
Run Code Online (Sandbox Code Playgroud)
看下面的方法:
public DateCalculatorTest(String actionTime, int expectedDayOfWeek) {
DateTimeFormatter dateTimeFormatter =
DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss ZZ");
DateTimeFormatter localTimeFormatter =
DateTimeFormatter.ofPattern("YYYY-MM-dd");
this.actionTime = dateTimeFormatter.parse(actionTime, ZonedDateTime::from);
this.expectedDayOfWeek = expectedDayOfWeek;
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法解析字符串。我收到以下错误:
Text '2017-02-12 06:59:00 +1300' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {WeekBasedYear[WeekFields[SUNDAY,1]]=2017, DayOfMonth=12, MonthOfYear=2, OffsetSeconds=46800},ISO resolved to 06:59 of type java.time.format.Parsed
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点java.time?
我在environmental声明性管道的指令部分有一组静态环境变量。这些值可用于管道中的每个阶段。我希望根据任意条件更改值。有没有办法做到这一点?
pipeline {
agent any
environment {
if ${params.condition} {
var1 = '123'
var2 = abc
} else {
var1 = '456'
var2 = def
}
}
stages {
stage('One') {
steps {
script {
...
echo env.var1
echo env.var2
...
}
}
}
}
stag('Two'){
steps {
script {
...
echo env.var1
echo env.var2
...
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试从同一个 Vagrant Base Box 启动 3 个虚拟机。但是,仅创建了 2 个 VM。这是因为在配置第二个 VM 期间,shell 配置程序脚本执行了两次。结果,该过程终止,并出现下面详述的错误。
这是我的 Vagrantfile:
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
#The box name and the URL to Retrieve the Vagrant Box from
config.vm.box = "eFx-Dev"
config.vm.box_url = "http://web/provisioning/vagrant-boxes/centos7-basev0.1.box"
config.ssh.insert_key = false
#Creating the first Dev Machine
#With network address being assigned via DHCP
#and bootstraped via a shell script.
#This script can be unique for each machine.
#But at the moment they are bootstarpped the same.
#The spects of the machine.
#Can …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Ansible 中以良好的格式显示调试命令的消息输出。目前输出如下:
TASK [stop : Report Status of Jenkins Process] *******************************************************************************************************************************
ok: [localhost] => {
"msg": "Service Jenkins is Running.\nReturn code from `grep`:\n0\n"
}
TASK [stop : debug] **********************************************************************************************************************************************************
ok: [localhost] => {
"msg": {
"changed": false,
"failed": false,
"msg": "Service Jenkins is Running.\nReturn code from `grep`:\n0\n"
}
}
Run Code Online (Sandbox Code Playgroud)
如何去掉 '\n' 字符并替换为新行?使用下面的代码split('\n')不起作用。
- name: Checking Jenkins Process
shell: "ps -ef | grep -v grep | grep -v dhclient | grep jenkins"
ignore_errors: yes
register: jenkins_process
- debug: …Run Code Online (Sandbox Code Playgroud) efx/
...
aws_account/
nonprod/
account-variables.tf
dev/
account-variables.tf
common.tf
app1.tf
app2.tf
app3.tf
...
modules/
tf_efxstack_app1
tf_efxstack_app2
tf_efxstack_app3
...
Run Code Online (Sandbox Code Playgroud)
在给定的环境(上面示例中的dev)中,我们有多个模块(app1,app2,app3等),这些模块基于我们在基础架构中运行的各个应用程序。
我正在尝试一次更新一个模块的状态(例如app1.tf)。我不确定该怎么做。
用例:我只希望将模块的LC之一更新为使用最新的AMI或安全组。
我在terrafrom中尝试了-target命令,但这似乎不起作用,因为它不检查terraform远程状态文件。
terraform plan -target=app1.tf
terraform apply -target=app1.tf
Run Code Online (Sandbox Code Playgroud)
因此,不进行任何更改。我相信这是Terraform 的错误。
有什么想法我可以做到这一点吗?
我有以下列表: appList = [DevOpsApplication, 01.01.01]
我想使用创建地图collectEntries。我知道it指的是迭代的当前元素( 的快捷方式{ it -> it })。因此,我尝试使用索引:
def appMap = appList.collectEntries { [(it[0]):it[1]] }
Run Code Online (Sandbox Code Playgroud)
然而,这给了我:
[D:e, 0:1]
Run Code Online (Sandbox Code Playgroud)
但我想要[DevOpsApplication: 01.01.01]。有没有办法做到这一点?
此外,将来我希望将其扩展到 2 个以上元素(例如[DevOpsApplication, 01.01.01, AnotherDevOpsApplication, 02.02.02]),并获得所需的输出[DevOpsApplication: 01.01.01, AnotherDevOpsApplication: 02.02.02]。这怎么可能呢?