[ansible-project] Re: Remove a line from file and surrounding
Thank you Jeff! I ended up using a shell script with sed. On Wednesday, June 15, 2022 at 1:37:01 PM UTC+2 Jeff S wrote: > You can use those *modules, replace & lineinfile*, to search for a > pattern and replace it with something. > ansible.builtin.replace module – Replace all instances of a particular > string in a file using a back-referenced regular expression — Ansible > Documentation > <https://docs.ansible.com/ansible/latest/collections/ansible/builtin/replace_module.html> > ansible.builtin.lineinfile module – Manage lines in text files — Ansible > Documentation > <https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html> > or use the *shell module* to work with sed! > > On Tuesday, June 14, 2022 at 4:59:38 PM UTC+2 Laci wrote: > >> >> So far my best option is to run a command which invokes sed >> On Tuesday, June 14, 2022 at 2:30:01 PM UTC+2 Laci wrote: >> >>> I'm working on a playbook which would remove lines from a file >>> containing specific hostname. >>> I want to use Ansible to remove the hostname AND surrounding lines. Here >>> is an example of a block that I need to remove: >>> >>> FileSet { >>> Name = "vcenter-hostname05" >>> Include { >>>Options { >>>signature = SHA1 >>>compression=GZIP >>>noatime=yes >>> } >>> Plugin = "vsphere: server=vsphere-vcenter host=hostname05.domain.com >>> abort_on_error" >>>} >>> } >>> >>> Does anyone have a suggestion how would I match the lines when all I >>> have is *hostname05*? >>> >> -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d3a2933c-0a29-45cb-99ea-031369b5a037n%40googlegroups.com.
[ansible-project] Re: Remove a line from file and surrounding
So far my best option is to run a command which invokes sed On Tuesday, June 14, 2022 at 2:30:01 PM UTC+2 Laci wrote: > I'm working on a playbook which would remove lines from a file containing > specific hostname. > I want to use Ansible to remove the hostname AND surrounding lines. Here > is an example of a block that I need to remove: > > FileSet { > Name = "vcenter-hostname05" > Include { >Options { >signature = SHA1 >compression=GZIP >noatime=yes > } > Plugin = "vsphere: server=vsphere-vcenter host=hostname05.domain.com > abort_on_error" >} > } > > Does anyone have a suggestion how would I match the lines when all I have > is *hostname05*? > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9341b01e-45ed-4afa-8421-0d57bf99affen%40googlegroups.com.
[ansible-project] Remove a line from file and surrounding
I'm working on a playbook which would remove lines from a file containing specific hostname. I want to use Ansible to remove the hostname AND surrounding lines. Here is an example of a block that I need to remove: FileSet { Name = "vcenter-hostname05" Include { Options { signature = SHA1 compression=GZIP noatime=yes } Plugin = "vsphere: server=vsphere-vcenter host=hostname05.domain.com abort_on_error" } } Does anyone have a suggestion how would I match the lines when all I have is *hostname05*? -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fc0cd7b8-9421-4a06-a1b9-0d129de3e7a8n%40googlegroups.com.
Re: [ansible-project] scan servers if package is installed and send email
Awesome, thank you very much! On Thursday, August 13, 2020 at 1:47:07 PM UTC-4, Vladimir Botka wrote: > > Laci, > > On Thu, 13 Aug 2020 08:47:31 -0700 (PDT) > Laci > wrote: > > > ... it finds the package only if no specific version is > > specified. For example it will find nginx and send email but won't > > find nginx-1.12.2 > > Try this. Loop "with_together" lists of packages' names and versions. > In the task's vars create list of the versions "pkgv". The > attribute "version" of the dictionary "ansible_facts.packages" is a > list because there may be more versions installed. In the condition > "when" test the searched version "item.1" is in the list "pkgv". > > vars: > - pkg_list: > - nginx-1.12.2 > - zip-3.0 > tasks: > - package_facts: > - debug: > msg: "Found {{ item.0 }}-{{ item.1 }}" > with_together: > - "{{ pkg_list| > map('regex_replace','^(.*)-(.*)$', '\\1')|list }}" > - "{{ pkg_list| > map('regex_replace','^(.*)-(.*)$', '\\2')|list }}" > when: pkgv|map('regex_search', '^' ~ item.1)|list|length > 0 > vars: > pkgn: "{{ ansible_facts.packages[item.0]|default([]) }}" > pkgv: "{{ pkgn|map(attribute='version')|list }}" > > Fit the condition to your needs. It's trivial to create a list of > found packages in the loop test it and send an email. > > -- > Vladimir Botka > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a99610b3-631b-4eba-8faa-3fbc9217fb43o%40googlegroups.com.
Re: [ansible-project] scan servers if package is installed and send email
Thank you Vladimir! This looks almost good, it finds the package only if no specific version is specified. For example it will find nginx and send email but won't find nginx-1.12.2 On Thursday, August 13, 2020 at 11:09:22 AM UTC-4, Vladimir Botka wrote: > > On Thu, 13 Aug 2020 07:20:51 -0700 (PDT) > Laci > wrote: > > > I'm looking for a playbook which would scan all servers and if a > particular > > package (ex: kernel-3.10.0-1062 or nginx-1.12.2-2) is installed would > send > > an email with the hostname. > > Did anyone do something alike? > > Collect "pkg_facts" and "intersect" the lists. For example > > vars: > - pkg_list: > - linux-image-5.4.0-42-generic > - nginx-1.12.2 > tasks: > - package_facts: > - mail: > subject: Packages found > body: "{{ send_pkg_list }}" > when: send_pkg_list|length > 0 > vars: > send_pkg_list: "{{ ansible_facts.packages.keys()| >intersect(pkg_list) }}" > > > > -- > Vladimir Botka > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c90de5b8-7441-46ac-8912-83990d6395dao%40googlegroups.com.
[ansible-project] scan servers if package is installed and send email
I'm looking for a playbook which would scan all servers and if a particular package (ex: kernel-3.10.0-1062 or nginx-1.12.2-2) is installed would send an email with the hostname. Did anyone do something alike? -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/18a34bc0-1368-4f97-9d05-bc8a15f70d66o%40googlegroups.com.
[ansible-project] Re: how to determine group's id?
Thank you, this did it: - name: set fact for group set_fact: group_id: "{{ getent_group.monitor[1] }}" - name: Add proc to fstab and mount it mount: path: /proc src: proc fstype: proc opts: "defaults,hidepid=2,gid={{ group_id }}" dump: 0 passno: 0 backup: true state: mounted -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/cebb1b7f-0c01-41b6-a419-f72ab83832deo%40googlegroups.com.
Re: [ansible-project] how to determine group's id?
Thank you guys, this fixes the first part. But how do I reuse the output of getent, I tried, the following but didn't work - getent: database: group - debug: var: getent_group.monitor - name: add line to fstab lineinfile: path: /etc/fstab line: proc/procprocdefaults,hidepid=2,gid={{ var }} 0 0 "The task includes an option with an undefined variable. The error was: 'var' is undefined -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bc51a905-f54b-44da-8a70-6c5645dcbc71o%40googlegroups.com.
[ansible-project] how to determine group's id?
Do you guys have a good idea what is the best way to determine a group's id them reuse that in a variable? For ex: % getent group monitor monitor:x:990:polkitd I need 990, then I have to add a line to /etc/fstab including 990 Thanks! -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/517da774-3826-4de3-b5da-17f128df2a68o%40googlegroups.com.
Re: [ansible-project] Abort playbook if host is not ready
Thank you! -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5e8badbb-a88c-451a-a114-868961464d97o%40googlegroups.com.
[ansible-project] ansible tower - command works BUT playbook fails to connect to the host via ssh
In my ansible tower I can execute a command successfully on a remote server, however when I try to run a playbook I get: { "msg": "Failed to connect to the host via ssh: Warning: Permanently added 'hostname,10.1.4.66' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey,gssapi-keyex,gssapi-with-mic,keyboard-interactive).", "unreachable": true, "changed": false } Seems to be a weird issue, did someone saw and solved this before? -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7ea6e452-bd00-408f-a1eb-36378bff57deo%40googlegroups.com.
[ansible-project] Abort playbook if host is not ready
Is there a good way to abort the playbook if host is not ready? For example I want to run a playbook against *thisserver*, but *thisserver* is unreachable by ssh or it is reachable but there is no python install. If any of these occurs I'd like to playbook to abort and stop processing tasks -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7d780f0d-3e70-4109-aaca-b63151b99ecd%40googlegroups.com.
Re: [ansible-project] Re: copy restricted files from server A to B
Thank you guys! It worked, this is the playbook for anyone having the same issues. At the end I added a test to remove files from buffer *serverA% ls -l* *-rw---. 1 root 6 May 20 16:11 ezaz.txt* - hosts: serverA gather_facts: no tasks: - name: fetch test file fetch: src=/tmp/ezaz.txt dest=/tmp/buffer/ flat=yes fail_on_missing=yes - hosts: serverB gather_facts: no tasks: - name: copy from dckr to dckr3 copy: src=/tmp/buffer/ezaz.txt dest=/tmp/final_ezaz.txt remote_src=no owner=root group=root mode=0400 backup=yes force=yes - hosts: ansible gather_facts: no tasks: - name: Delete certificates from /tmp file: path=/tmp/buffer/ezaz.txt state=absent *serverB% ls -l* *-r. 1 root root 6 May 20 16:30 final_ezaz.txt* On Tuesday, May 19, 2020 at 4:50:10 PM UTC-4, Jean-Yves LENHOF wrote: > > Use copy (to copy on the second server), fetch (to get the file on the > controller), and stat (to get rights) modules > > Regards, > > JYL > > > Le 19/05/2020 à 22:38, Laci a écrit : > > Another detail is that serverA can't talk to serverB or vice versa, only > the Ansible server can talk to both of them > > On Tuesday, May 19, 2020 at 2:29:49 PM UTC-4, Laci wrote: >> >> I have some files with 0400/-r permissions on server A that I >> need to copy to server B and preserve permissions. >> >> For example: >> serverA:/etc/ssl_cert.key -> serverB:/etc/ssl_cert.key >> >> How would you do it? >> > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to ansible...@googlegroups.com . > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/ef9d3a60-a5c2-4f13-97dc-0e4d41c8582a%40googlegroups.com > > <https://groups.google.com/d/msgid/ansible-project/ef9d3a60-a5c2-4f13-97dc-0e4d41c8582a%40googlegroups.com?utm_medium=email_source=footer> > . > > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e3ebb453-58dd-4d7d-8df9-486068f4473e%40googlegroups.com.
[ansible-project] Re: copy restricted files from server A to B
Another detail is that serverA can't talk to serverB or vice versa, only the Ansible server can talk to both of them On Tuesday, May 19, 2020 at 2:29:49 PM UTC-4, Laci wrote: > > I have some files with 0400/-r permissions on server A that I need > to copy to server B and preserve permissions. > > For example: > serverA:/etc/ssl_cert.key -> serverB:/etc/ssl_cert.key > > How would you do it? > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ef9d3a60-a5c2-4f13-97dc-0e4d41c8582a%40googlegroups.com.
[ansible-project] copy restricted files from server A to B
I have some files with 0400/-r permissions on server A that I need to copy to server B and preserve permissions. For example: serverA:/etc/ssl_cert.key -> serverB:/etc/ssl_cert.key How would you do it? -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9526fdcf-2dd7-403c-92fe-564b32ef934c%40googlegroups.com.
Re: [ansible-project] escaping curly braces in lineinfile module
Another task I'm working on is a conditional blockinfile, something like: if OS=BSD do this, if Linux do that. I need this because there is a slightly different configuration for them: BSD: Job { Name= "serverX" Client = "serverX-fd" JobDefs = "DefaultJob" } Linux: Job { Name= "serverX" Client = "serverX-fd" JobDefs = "DefaultJob" FileSet = "linux" } On Thursday, May 14, 2020 at 10:31:36 AM UTC-4, Laci wrote: > > Actually this is my goal. > We are going to have add new servers every time to this file. > > So the following lines will be repeated X times > Job { > Name= "serverX" > Client = "serverX-fd" > JobDefs = "DefaultJob" > } > >> >> "Using a custom marker without the {mark} variable may result in the >> block >>being repeatedly inserted on subsequent playbook runs." >> >> >> -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3b17e950-1ea1-4734-9b38-3746c44ac1ee%40googlegroups.com.
Re: [ansible-project] escaping curly braces in lineinfile module
Actually this is my goal. We are going to have add new servers every time to this file. So the following lines will be repeated X times Job { Name= "serverX" Client = "serverX-fd" JobDefs = "DefaultJob" } > > "Using a custom marker without the {mark} variable may result in the > block >being repeatedly inserted on subsequent playbook runs." > > > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/859bc5dd-d084-42b9-b581-aff2b2ddbae9%40googlegroups.com.
Re: [ansible-project] escaping curly braces in lineinfile module
Thank you vlado, this worked for me: blockinfile: path: /conf.d/jobs.inc marker: " " block: | Job { Name= "{{ remote_shorthost }}" Client = "{{ remote_shorthost }}-fd" JobDefs = "DefaultJob" } backup: yes On Tuesday, May 12, 2020 at 3:47:30 PM UTC-4, Vladimir Botka wrote: > > On Tue, 12 May 2020 12:32:11 -0700 (PDT) > Laci > wrote: > > > % cat jobs.inc > > Job { > > Name= "server1" > > Client = "server1-fd" > > JobDefs = "DefaultJob" > > } > > Job { > > Name= "server2" > > Client = "server2-fd" > > JobDefs = "DefaultJob" > > } > > > > How would I add server3? > > The best option in this case would be "template" > > https://docs.ansible.com/ansible/latest/modules/template_module.html#template-template-a-file-out-to-a-remote-server > > > If the editing can't be avoided then "blockinfile" might do the job > https://docs.ansible.com/ansible/latest/modules/blockinfile_module.html > > HTH, > > -vlado > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/089fe3f6-2fb8-43af-a310-18b58ef78809%40googlegroups.com.
[ansible-project] escaping curly braces in lineinfile module
I am new in Ansible world. I spent some time solving this but got to the point when I need to ask: I have a file called jobs.inc and I need to add six lines with Ansible. Here is an example % cat jobs.inc Job { Name= "server1" Client = "server1-fd" JobDefs = "DefaultJob" } Job { Name= "server2" Client = "server2-fd" JobDefs = "DefaultJob" } How would I add server3? The following playbooks are the ones I tried and they didn't work. Thank you! 1) - name: add new lines to jobs.inc lineinfile: path: /conf.d/jobs.inc line: "{{ item }}" with_items: - Job {% raw %}{{% endraw %} -Name= "{{ remote_shorthost }}" -Client = "{{ remote_shorthost }}-fd" -JobDefs = "DefaultJob" - {% raw %}}{% endraw %} 2) - name: add new lines to jobs.inc lineinfile: path: /conf.d/jobs.inc line: "{{ item }}" with_items: - Job { -Name= "{{ remote_shorthost }}" -Client = "{{ remote_shorthost }}-fd" -JobDefs = "DefaultJob" - } 3) vars: curly1_variable: !unsafe '{' curly2_variable: !unsafe '}' tasks: - name: add new lines to jobs.inc lineinfile: path: /conf.d/jobs.inc line: "{{ item }}" with_items: - Job !unsafe curly1_variable -Name= "{{ remote_shorthost }}" -Client = "{{ remote_shorthost }}-fd" -JobDefs = "DefaultJob" - !unsafe curly2_variable -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d909fb86-154c-4485-be51-f27139142b6a%40googlegroups.com.