用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
最满意答案
此代码适用于您的示例:
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). Thewhich.max
function returns the first position where it's argument is the maximum of the vector. Since The vectors returned byx != 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 thenchar
function:df$z[as.character(df$x) == as.character(df$y)] <- nchar(as.character(df$x[as.character(df$x) == as.character(df$y)]))
相关问答
更多-
按行部分字符串匹配(Partial String Matching by Row)[2023-04-22]
此代码适用于您的示例: 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 作为概要, strspl ... -
从部分字符串匹配创建新的pandas数据帧(Creating new pandas dataframe from partial string match [duplicate])[2022-05-31]
其他方式: 国际: df_international = df[df['Book'].str.contains('International')].reset_index(drop=True) df_international.loc[:, 'Book'] = 'International' print(df_international) # Description Book Product ID #0 Products International ... -
LINQ中的部分字符串匹配(Partial string matching in LINQ)[2021-12-24]
大多数LINQ - > SQL转换器将从c#中取出一些常规方法,并将它们转换为SQL。 Contains是翻译和使用linq2sql和EF的非常常见的方法 var names = from cust in customers where cust.FirstName.Contains("IS") select cust; 编辑:(不区分大小写) var names = from cust in customers where cu ... -
你可以使用fuzzywuzzy模块 from fuzzywuzzy import fuzz fuzz.partial_ratio("Harley Davidson","Hardley Davidson") 93 有关模糊wuzzy的更多信息,请尝试此链接 You could use fuzzywuzzy module from fuzzywuzzy import fuzz fuzz.partial_ratio("Harley Davidson","Hardley Davidson") 93 For mo ...
-
字符串匹配(String Matching)[2024-01-05]
匹配"///RT///"和"///RATE///" 。 I don't know it will work every time or not.But I have tried this and it works right now in this string matching. I want to know whether this is ok or not,please give me suggestion. str1 = str1.Insert(0, "///"); str1=str1.Insert ... -
构造一个布尔矩阵M,其中M(i,j)告诉你一个字符串的第i个字符是否与另一个字符串的第j个字符匹配。 匹配的子串现在将是M中的对角线,所以现在走遍矩阵并寻找那些。 Construct a boolean matrix M where M(i,j) tells you if the i'th character of one string matches the j'th character of the other. A matching substring will now be a diagonal l ...
-
字符串部分匹配(String partial match)[2024-03-17]
这应该是诀窍: if (s2.contains(s1)) return s2; This should do the trick: if (s2.contains(s1)) return s2; -
SQL-服务器 SELECT TOP (1) * FROM yourTable WHERE CUST_TYPE = @cust_type AND POST_CODE = LEFT( @postal_code, LEN(POST_CODE) ) ORDER BY LEN(POST_CODE) DESC 神谕 (我现在不能测试:) SELECT * FROM ( SELECT * FROM yourTable WHERE ...
-
试试这个让我知道。 私有函数GetColumnNumber(strKeyword As String)作为整数 Dim rngColLoop As Range Dim intCounter As Integer Dim intColNum As Integer Dim intPrevious As Integer Dim intCurrent As Integer lngCounter = 0 Wit ...
-
如果要捕获不区分大小写,则需要包含i标志。 此外,如果要保留原始案例而不是使用term替换它,可以使用捕获组,如下所示: const str = 'This is an Example'; const term = 'exam'; const result = str.replace(new RegExp(`(${term})`, 'gi'), '$1'); console.log(result); If you want to capture with case ...