首页 \ 问答 \ 用ansible安装指南针(install compass with ansible)

用ansible安装指南针(install compass with ansible)

我正在尝试使用Ansible在EC2服务器上安装罗盘,这是我们的一项服务所需要的。 通常我们使用以下命令手动安装它 -

curl -L https://get.rvm.io | bash -s stable
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.1.2
rvm use 2.1.2 --default
gem install compass

然后成功运行指南针编译。 现在,当我尝试使用Ansible playbook(使用shell模块)运行这些命令时,系统找不到compass命令。

我曾尝试使用RVM官方Ansible角色( https://github.com/rvm/rvm1-ansible ),而我得到的只是更多错误。

我尝试使用apt安装rubydev和rubygems-integration,然后使用gem模块安装gem。 这确实识别了罗盘命令但是当我尝试编译甚至显示罗盘版本时它会返回错误。 以下是运行指南针-v的错误,例如:

Errno::ENOENT on line ["25"] of /usr/lib/ruby/vendor_ruby/compass/version.rb: No such file or directory - /usr/lib/ruby/vendor_ruby/compass/../../VERSION.yml
Run with --trace to see the full backtrace  

这是设法安装罗盘的剧本,但给我留下了我提到的错误:

---
- hosts: "{{ host_name }}"
  become: yes
  become_method : sudo
  tasks:
    - name: install ruby-dev
      apt: 
        name: ruby-dev
    - name: install rubygems
      apt: 
        name: rubygems-integration
    - name: install ruby compass
      apt: 
        name: ruby-compass
  ...

会喜欢一些帮助。


I'm trying to use Ansible to install compass, which is needed for one of our services, on an EC2 server. Usually we install it manually using the following commands -

curl -L https://get.rvm.io | bash -s stable
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.1.2
rvm use 2.1.2 --default
gem install compass

And then run compass compile successfully. Now when I try to run these commands with an Ansible playbook (using the shell module) the compass command is not found by the system.

I have tried using RVM official Ansible role (https://github.com/rvm/rvm1-ansible), and all I got is more errors.

I've tried installing rubydev and rubygems-integration using apt and then installing the gem using the gem module. This does recognise the compass command but when I try to compile or even show the compass version it returns errors. Here is the error for running compass -v, for example:

Errno::ENOENT on line ["25"] of /usr/lib/ruby/vendor_ruby/compass/version.rb: No such file or directory - /usr/lib/ruby/vendor_ruby/compass/../../VERSION.yml
Run with --trace to see the full backtrace  

This is the playbook that managed to install compass, but left me with the errors I've mentioned:

---
- hosts: "{{ host_name }}"
  become: yes
  become_method : sudo
  tasks:
    - name: install ruby-dev
      apt: 
        name: ruby-dev
    - name: install rubygems
      apt: 
        name: rubygems-integration
    - name: install ruby compass
      apt: 
        name: ruby-compass
  ...

Would love some help.


原文:https://stackoverflow.com/questions/35383184
更新时间:2022-10-03 18:10

最满意答案

此代码适用于您的示例:

df$z <- mapply(function(x, y) which.max(x != y),
               strsplit(as.character(df$x), split=""),
               strsplit(as.character(df$y), split="")) - 1

df
       x    y z
1    yhf   yh 2
2 rnmqjk rnmj 3
3    wok   ok 0

作为概要, strsplit将字符串向量拆分为字符向量列表。 这里,矢量的每个元素都是单个字符(split =“”参数)。 which.max函数返回第一个位置,其中参数是向量的最大值。 由于x != y返回的向量是逻辑的,因此which.max返回观察到差异的第一个位置。 mapply接受一个函数并列出并将提供的函数应用于列表的相应元素。

请注意,这会产生警告:字符串的长度不匹配。 这可以通过几种方法解决,如果邮件错误,最简单的方法是将函数封装在suppressWarnings


正如OP注释中的那样,如果存在整个单词匹配的实例,则which.max返回1.为了返回与字符串相同的长度,我将添加第二行代码,将逻辑子集与nchar函数结合起来:

df$z[as.character(df$x) == as.character(df$y)] <-
                        nchar(as.character(df$x[as.character(df$x) == as.character(df$y)]))

This code works for your example:

df$z <- mapply(function(x, y) which.max(x != y),
               strsplit(as.character(df$x), split=""),
               strsplit(as.character(df$y), split="")) - 1

df
       x    y z
1    yhf   yh 2
2 rnmqjk rnmj 3
3    wok   ok 0

As an outline, strsplit splits a string vector into a list of character vectors. Here, each element of a vector is a single character (with the split="" argument). The which.max function returns the first position where it's argument is the maximum of the vector. Since The vectors returned by x != y are logical, which.max returns the first position where a difference is observed. mapply takes a function and lists and applies the provided function to corresponding elements of the lists.

Note that this produces warnings that the lengths of the strings don't match. This could be addressed in a couple of ways, the easiest is wrapping the function in suppressWarnings if the messages bug you.


As the OP notes int the comments if there are instances where the entire word matches, then which.max returns 1. To return the same length as the string, I'd add a second line of code that combines logical subsetting with the nchar function:

df$z[as.character(df$x) == as.character(df$y)] <-
                        nchar(as.character(df$x[as.character(df$x) == as.character(df$y)]))

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)