我正在使用 Ansible,在运行我的 playbook 后收到此错误。
这是我的剧本:
---
- name: Set 192.168.122.4 Hostname
hosts: 192.168.122.4
gather_facts: false
become: true
tasks:
- name : Name 4
hostname:
name: ansible1.example.com
- name: Set 192.168.122.5 Hostname
hosts: 192.168.122.5
gather_facts: false
become: true
tasks:
- name : Name 5
hostname:
name: ansible2.example.com
- name: Manage Hosts File
hosts: all
gather_facts: true
become: true
tasks:
- name: Deploy Hosts Template
template:
src: hosts.j2
dest: /etc/hosts
Run Code Online (Sandbox Code Playgroud)
这是我的模板
# Managed by Ansible
127.0.0.1 localhost
{% for host in groups['all'] …Run Code Online (Sandbox Code Playgroud) 我做了以下步骤:
git clone https://github.com/nibtehaz/NORTH-app.git
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install # which caused the following error
Run Code Online (Sandbox Code Playgroud)
并得到
The following packages have unmet dependencies:
nodejs : Conflicts: npm
npm : Depends: node-gyp (>= 3.6.2~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
Run Code Online (Sandbox Code Playgroud)
我做了建议的事情,但它导致了另一个问题:
sudo apt install node-gyp
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not …Run Code Online (Sandbox Code Playgroud) 假设 df 命令返回以下内容。
[john.doe@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 372607 170989 177862 50% /boot
/dev/sda2 129774 6994 122780 6% /
Run Code Online (Sandbox Code Playgroud)
借助 Ansible,我可以使用 shell 模块捕获 /dev/sda1 的可用值 (177862)。
[john.doe@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 372607 170989 177862 50% /boot
/dev/sda2 129774 6994 122780 6% /
Run Code Online (Sandbox Code Playgroud)
这将显示类型是AnsibleUnsafeText。如果我对 Gather_facts 执行相同操作,也会返回 AnsibleUnsafeText。我不知道如何使类型成为整数而不是 AnsibleUnsafeText。
TASK [standard out]
ok: [localhost] => {
"msg": "122780"
}
TASK [type]
ok: [localhost] => {
"msg": "AnsibleUnsafeText"
} …Run Code Online (Sandbox Code Playgroud) 为什么我无法使用来更改返回changed_when的任务的状态?failedchanged
例如,我有一个自定义模块,允许我检查卷是否存在,如果卷不存在,它将失败。
剧本片段:
---
- name: Example ansible playbook
tasks:
- name: Check existence of the volume
custom_name_space_my_volume:
name: ABC #name of the volume
changed_when: true
Run Code Online (Sandbox Code Playgroud)
如果该卷ABC不存在,则结果为failed。但为什么没有change_when: true导致结果返回changed呢?
注意:上面的例子可能没有逻辑意义,因为它没有做一些有用的事情。但我只是想用它作为我的问题的样本。
我正在使用cross_val_scorefrom scikit-learn (package sklearn.cross_validation) 来评估我的分类器。
如果我f1用于scoring参数,该函数将返回一个类的 f1 分数。为了获得我可以使用的平均值,f1_weighted但我不知道如何获得其他班级的 f1 分数。(准确率和召回率类似)
中的函数sklearn.metrics有一个labels执行此操作的参数,但我在文档中找不到类似的内容。
有没有办法一次获得所有类的 f1 分数,或者至少指定应该考虑的类cross_val_score?
我正在尝试提高 ansible playbook 的性能。我有一个测试剧本如下:
---
- name: Test
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Creating an empty file
file:
path: /tmp/hello
state: touch
- name: Test
command: "echo 'Hello, World!' >> /tmp/hello"
with_sequence: start=1 end=500
delegate_to: localhost
Run Code Online (Sandbox Code Playgroud)
运行这需要惊人的 57 秒。与执行相同操作的 bash 脚本相比:
测试文件
#!/bin/bash
touch /tmp/hello
for i in {1..500}
do
sh /home/admin/hello.sh
echo "This is iteration $i"
done
Run Code Online (Sandbox Code Playgroud)
你好.sh
#!/bin/bash
echo "Hello, World!" >> /tmp/hello
Run Code Online (Sandbox Code Playgroud)
这需要大约 1.5 秒才能运行。
我已经对ansible.cfg文件进行了一些更改
[ssh_connection]
ssh_args = -o ControlMaster=auto …Run Code Online (Sandbox Code Playgroud) 我想使用这些配置部署 MySql 数据库服务器。
\n这是我部署 MySql 的剧本:
\n- name: "Inclure le fichier : install_utilitaires_mysql.yaml"\n include: install_utilitaires_mysql.yaml\n when: ansible_os_family == "Debian"\n\n- name: "Telechargement d\'un package .deb pour ajouter le repo mysql"\n get_url:\n url: https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb\n dest: /tmp\n when: ansible_os_family == "Debian"\n\n- name: "Installation du package .deb"\n apt:\n deb: /tmp/mysql-apt-config_0.8.15-1_all.deb\n when: ansible_os_family == "Debian"\n\n- name: "Mise a jour des sources list : apt update"\n apt:\n update_cache: yes\n when: ansible_os_family == "Debian"\n\n- name: "Installation de MySql"\n apt:\n name: mysql-server\n state: latest\n when: ansible_os_family …Run Code Online (Sandbox Code Playgroud) 我收到以下错误docker-compose:
docker-compose up -d\nERROR: yaml.scanner.ScannerError: while scanning a simple key\n in "./docker-compose.yml", line 4, column 1\ncould not find expected ':'\n in "./docker-compose.yml", line 5, column 1\nRun Code Online (Sandbox Code Playgroud)\n这是我的docker-compose.yaml:
version: '2.0'\nservices:\n\n\xc2\xa0 #PHP Service\n\xc2\xa0 app:\n\xc2\xa0\xc2\xa0\xc2\xa0 build:\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 context: .\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 dockerfile: Dockerfile\n\xc2\xa0\xc2\xa0\xc2\xa0 image: cloudsigma.com/php\n\xc2\xa0\xc2\xa0\xc2\xa0 container_name: app\n\xc2\xa0\xc2\xa0\xc2\xa0 restart: unless-stopped\n\xc2\xa0\xc2\xa0\xc2\xa0 tty: true\n\xc2\xa0\xc2\xa0\xc2\xa0 environment:\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 SERVICE_NAME: app\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 SERVICE_TAGS: dev\n\xc2\xa0\xc2\xa0\xc2\xa0 working_dir: /var/www/html/\n\xc2\xa0\xc2\xa0\xc2\xa0 volumes:\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 - ./:/var/www/html/\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 - ./php/laravel.ini:/usr/local/etc/php/conf.d/laravel.ini\n\xc2\xa0\xc2\xa0\xc2\xa0 networks:\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 - app-network\nRun Code Online (Sandbox Code Playgroud)\n有人可以告诉我我的撰写文件有什么问题吗?
\n尝试使用docker-compose该模块在 ansible 剧本中使用docker_compose。请注意,我可以在 ansible 中成功使用 docker 模块,但遇到docker_compose模块问题。我使用纯文本变量进行本地测试,使用 ansible-vault 来存储机密。
在 ansible 文档中,它解释说他们的 docker-compose 模块仅支持 docker-compose 的版本 1 和 2。
这是我的docker-compose.yml:
---
version: "2.4"
services:
my_demo:
build: .
networks:
demo_net:
ipv4_address: 172.0.1.2
ports:
- 8080:8080
image: demo_image
networks:
demo_net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.0.1.0/30
gateway: 172.0.1.1
Run Code Online (Sandbox Code Playgroud)
这是我的main.yml:
---
- hosts: localhost
connection: local
become: true
vars:
- ansible_sudo_pass: password
- ansible_python_interpreter: /usr/bin/python3
tasks:
- name: Docker compose …Run Code Online (Sandbox Code Playgroud)