我必须使用Ansible模块才能编辑ssl.conf文件-每次导入新证书时。 目前,我正在使用shell模块执行sed命令,但如果可能的话,我想使用lineinfile
sed -i '/^SSLRequire/ s/.$/|^.*.us-gov-vodafone-1.*\//' ssl.conf -i_backup_$(date "+%m%d%y")
给定的sed将删除行尾的/,并附加'| ^。 .us-gov-vodafone-1。 /'
我尝试了不同的方法来实现它,但是没有。
任何建议都将受到感激。
我尝试了下面的代码,但没有给我适当的结果
---
- hosts: ub2
# user: ansible
vars:
test:
- '|^.*.us-gov-vodafone-1.*/'
tasks:
- name: append reguler expression
lineinfile:
dest: /tmp/ssl.conf
backrefs: yes
state: present
regexp: '^(SSLRequire(?!.*\b{{ test }}\b).*)$'
line: '\1 {{ test }}'
PLAY [ub2] ***************************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [192.168.56.102]
TASK [append reguler expression] *****************************************************************************************************************************
fatal: [192.168.56.102]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.56.102 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1546198717.33-9064765281500/AnsiballZ_lineinfile.py\", line 113, in <module>\r\n _ansiballz_main()\r\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1546198717.33-9064765281500/AnsiballZ_lineinfile.py\", line 105, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1546198717.33-9064765281500/AnsiballZ_lineinfile.py\", line 48, in invoke_module\r\n imp.load_module('__main__', mod, module, MOD_DESC)\r\n File \"/tmp/ansible_lineinfile_payload_LyoFsx/__main__.py\", line 524, in <module>\r\n File \"/tmp/ansible_lineinfile_payload_LyoFsx/__main__.py\", line 515, in main\r\n File \"/tmp/ansible_lineinfile_payload_LyoFsx/__main__.py\", line 264, in present\r\n File \"/usr/lib/python2.7/re.py\", line 194, in compile\r\n return _compile(pattern, flags)\r\n File \"/usr/lib/python2.7/re.py\", line 251, in _compile\r\n raise error, v # invalid expression\r\nsre_constants.error: bad character range\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
to retry, use: --limit @/home/ansible/find_and_append_2.retry
PLAY RECAP ***************************************************************************************************************************************************
192.168.56.102 : ok=1 changed=0 unreachable=0 failed=1