Re: [ansible-project] deferred evaluation (?)

2023-07-27 Thread Vladimir Botka
Create a template. For example,

shell> cat create_test.j2
{% for i in strings %}
{{ i }} = {{ '{{' }} {{ i }} {{ '}}' }}
{% endfor %}

Then, the below playbook

shell> cat pb.yml
- hosts: localhost
  tasks:
- template:
src: create_test.j2
dest: /tmp/test.j2
  vars:
strings:
  - '0'
  - '1'
  - "['aa', 'bb', 'cc']|intersect(['bb', 'cc'])"
  - "['aa', 'bb', 'cc']|intersect(['bb', 'cc'])|length > 0"
- debug:
msg: "{{ lookup('template', '/tmp/test.j2') }}"

gives abridged

  msg: |-
0 = 0
1 = 1
['aa', 'bb', 'cc']|intersect(['bb', 'cc']) = ['bb', 'cc']
['aa', 'bb', 'cc']|intersect(['bb', 'cc'])|length > 0 = True

-- 
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/20230728052731.289a5791%40gmail.com.


pgpgWSQj23O6C.pgp
Description: OpenPGP digital signature


Re: [ansible-project] deferred evaluation (?)

2023-07-27 Thread Todd Lewis
Sure. Here's a complete example where the debug task's output msg 
contains exactly what I want. However, instead of each item being a 
3-element list of strings, I want to pass in a single string, and use 
that string in various ways within the msg: expressions to accomplish 
the same thing.


To be clear: as presented below, this problem isn't worth solving. After 
all, there's the playbook down below already! But that's not the point. 
The point is to understand effective /run-time/ techniques to build 
strings containing Jinja2 expressions and have them evaluated. 
("Templated" I guess is the verb rather than "evaluated," but that feels 
backwards. In my brain, "to template" means to examine a sufficiently 
large set of outputs and create a template adequate to reproduce those 
outputs from reasonable inputs. But I digress.)


Apparently it's possible to write such strings to a file and use 
lookup('template',tmpfilename), but there doesn't seem to be the 
equivalent of lookup('template',jinja2_expression_string). Not that I 
have found anyway.


[utoddl@tango ansible]$*cat deferred.yml*  
---

# deferred.yml
- name: Deferred evaluation demo
  hosts: localhost
  gather_facts: false
  tasks:
- name: Evaluate booleanness of various expressions
  ansible.builtin.debug:
msg:
  - '{{ item.0 }}'
  - '{{ item.1 }}'
  - '{{ item.2 }}'
  loop:
- [   "0",
   "{{ 0 }}",
   "{{ 0 | bool }}"]
- [   "1",
   "{{ 1 }}",
   "{{ 1 | bool }}"]
- [   "2",
   "{{ 2 }}",
   "{{ 2 | bool }}"]
- [   "['aa', 'bb', 'cc'] | intersect(['bb', 'cc'])",
   "{{ ['aa', 'bb', 'cc'] | intersect(['bb', 'cc']) }}",
   "{{ ['aa', 'bb', 'cc'] | intersect(['bb', 'cc']) | bool }}"]
- [   "['aa', 'bb', 'cc'] | intersect(['bb', 'cc']) | length > 0",
   "{{ ['aa', 'bb', 'cc'] | intersect(['bb', 'cc']) | length > 0 }}",
   "{{ ['aa', 'bb', 'cc'] | intersect(['bb', 'cc']) | length > 0 | bool 
}}"]
[utoddl@tango ansible]$*ansible-playbook deferred.yml*

PLAY [Deferred evaluation demo] 
*

TASK [Evaluate booleanness of various expressions] 
**
ok: [localhost] => (item=['0', '0', False]) => {
"msg": [
"0",
"0",
false
]
}
ok: [localhost] => (item=['1', '1', True]) => {
"msg": [
"1",
"1",
true
]
}
ok: [localhost] => (item=['2', '2', False]) => {
"msg": [
"2",
"2",
false
]
}
ok: [localhost] => (item=["['aa', 'bb', 'cc'] | intersect(['bb', 'cc'])", ['bb', 
'cc'], False]) => {
"msg": [
"['aa', 'bb', 'cc'] | intersect(['bb', 'cc'])",
[
"bb",
"cc"
],
false
]
}
ok: [localhost] => (item=["['aa', 'bb', 'cc'] | intersect(['bb', 'cc']) | length > 
0", True, True]) => {
"msg": [
"['aa', 'bb', 'cc'] | intersect(['bb', 'cc']) | length > 0",
true,
true
]
}

PLAY RECAP 
**
localhost  : ok=1changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0


On 7/27/23 6:03 PM, Vladimir Botka wrote:

post expected result



--
Todd

--
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/ce2582b2-add4-5806-8523-d44ef7f1bcb9%40gmail.com.


Re: [ansible-project] deferred evaluation (?)

2023-07-27 Thread Vladimir Botka
post expected result

-- 
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/20230728000322.23e6f83b%40gmail.com.


pgpsIXqSvv9xn.pgp
Description: OpenPGP digital signature


Re: [ansible-project] deferred evaluation (?)

2023-07-27 Thread Todd Lewis
I'm confused. The template lookup wants a [list of] file[s]. I'd rather not 
write these strings out to temp files just to get them templated. Or am I 
misinterpreting your suggestion?

On Thursday, July 27, 2023 at 4:52:24 PM UTC-4 Brian Coca wrote:

> try the template lookup
>
> -- 
> --
> Brian Coca
>
>

-- 
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/882015ee-42c8-42db-828d-e1b6a4697e5dn%40googlegroups.com.


Re: [ansible-project] deferred evaluation (?)

2023-07-27 Thread Brian Coca
try the template lookup

-- 
--
Brian Coca

-- 
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/CACVha7d_Uenwa9KKNScbC7RXfuxzpg9FM-%3D9cQa_9_FhROH1NQ%40mail.gmail.com.


[ansible-project] deferred evaluation (?)

2023-07-27 Thread Todd Lewis
I'm trying to loop over a set of strings with ansible.builtin.debug, and I 
want to produce a three-part message for each string, like this:

- name: Demo expressions
  ansible.builtin.debug:
msg:
  - '{{ item }}'
  - '*evaluate item as a Jinja2 expression*'
  - '*like previous, but with "| bool" appended*'
  loop:
- "0"
- "1"
- "2"
- "['aa', 'bb', 'cc'] | intersect(['bb', 'cc'])"
- "['aa', 'bb', 'cc'] | intersect(['bb', 'cc']) | length > 0"

The first part of the message should show the string, and it does.
The second part somehow needs to show the result of evaluating the string 
as a Jinja2 expression.
The third part is supposed to append "| bool" onto the string, evaluate 
_that_ as a Jinja2 expression, and show the result.

I feel like there should be some way to do this with lookup('items',...), 
but I'm having no luck. I'd appreciate any suggestions. Thanks,
--
Todd

-- 
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/00fa51d7-9290-4243-970f-d00be019c4ban%40googlegroups.com.


Re: [ansible-project] edit string in a multi-line file

2023-07-27 Thread Todd Lewis

Here's one solution. It uses backrefs and a negative lookahead assertion.

- name: Test lineinfile
  hosts: localhost
  gather_facts: false
  tasks:
- name: Create a file to work on
  ansible.builtin.copy:
content: |
   First line of a file
   Second line of the same file
   This is a file and I am editing it. Extra Stuff!
   Fourth line of this file
dest: /tmp/textfile.txt

- name: Show the file content
  ansible.builtin.debug:
msg: "{{ lookup('file', '/tmp/textfile.txt') }}"

- name: Insert "new" before "file" in the 3rd line
  ansible.builtin.lineinfile:
path: /tmp/textfile.txt
regexp: '(This is a )(?!>new)(file and I am editing it\..*)'
backrefs: true
line: '\1new \2'

- name: Show the file content a 2nd time
  ansible.builtin.debug:
msg: "{{ lookup('file', '/tmp/textfile.txt') }}"

- name: Second identical lineinfile should not make changes
  ansible.builtin.lineinfile:
path: /tmp/textfile.txt
regexp: '(This is a )(?!>new)(file and I am editing it\..*)'
backrefs: true
line: '\1new \2'

- name: Show the file content a 3nd time
  ansible.builtin.debug:
msg: "{{ lookup('file', '/tmp/textfile.txt') }}"


On 7/27/23 9:13 AM, Kathy L wrote:
I am trying to edit a string in a multi-line file.  For instance, if I 
had this string:


This is a file and I am editing it

I want to add the string "new" in front of file /if/ it does not exist 
already.


I've tried lineinfile, but the issue is that I don't know what else is 
on the line.  There could be more data after "This is a file and I am 
editing it" that I don't want to change. What is the best way to do this?



--
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/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com 
.


--
Todd

--
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/35c0b998-066a-32aa-570f-d847c055ae5b%40gmail.com.


Re: [ansible-project] Ansible Tower error of Deploying Dynatrace Oneagent on Windows Host | "unexpected rc from install C:\Temp\dynatrace-oneagent-windows-latest.exe: see rc, stdout and stderr for mor

2023-07-27 Thread Pradeep Reddy
Hello All,

I am looking for dynatrace oneagent ansible playbook for windows 
installation. Could someone please share the steps for installation?

Thanks,
Pradeep  

On Wednesday, 8 April 2020 at 19:05:48 UTC+5:30 Stefan Hornburg (Racke) 
wrote:

> On 4/8/20 3:33 PM, Richard Jusay wrote:
> > Hi,
> > 
> > I'm installing Dynatrace oneagent on Windows server, successfully 
> downloaded the installer but it wont continue the
> > installation because of this error.
>
> Hello Richard,
>
> please reach out to RedHat Support, this list is only for Ansible and not 
> for Tower nor AWX.
>
> Regards
> Racke
>
> > 
> > *Ansible Tower*
> > Play: dynatrace oneagent install on windows
> > Task: install:execute oneagent install file
> > Module: win_package
> > 
> > {
> > "stderr_lines": [],
> > "_ansible_no_log": false,
> > "stdout": "",
> > "changed": false,
> > "reboot_required": false,
> > "stderr": "",
> > "rc": 1602,
> > "msg": "unexpected rc from install 
> C:\Temp\dynatrace-oneagent-windows-latest.exe: see rc, stdout and stderr 
> for more
> > details",
> > "stdout_lines": []
> > }
> > 
> > *Exact Error:*
> > TASK [install: execute oneagent install file] 
> **
> > fatal: [10.250.8.179]: FAILED! => {"changed": false, "msg": "unexpected 
> rc from install
> > C:\Temp\dynatrace-oneagent-windows-latest.exe: see rc, stdout and stderr 
> for more details", "rc": 1602,
> > "reboot_required": false, "stderr": "", "stderr_lines": [], "stdout": 
> "", "stdout_lines": []}
> > 
> > 
> > 
> > *Playbook:*
> > 
> > 
> > dynatrace oneagent install on windows
> > 
> > 
> > hosts_group -> inventory group of hosts to execute playbook on
> > 
> > 
> > dt_api_endpoint -> dynatrace environment api endpoint (include trailing 
> /)
> > 
> > 
> > dt_api_token -> dynatrace api install token
> > 
> > 
> > dt_host_group: -> dynatrace host group name
> > 
> > 
> > dt_app_log_content_access: -> flag to enable or disable log analytics on 
> host (0 or 1)
> > 
> > 
> > dt_infra_only: -> flag to set cloud infrastructure monitoring mode on 
> host (0 or 1)
> > 
> > 
> > {65E3C889-BF02-4A22-9E22-5DCA88789582} v1.183.109 - live
> > 
> > 
> > {73CFAADA-499D-4B5F-A7D4-9687DDBDCAF5} v1.183.151 - practice
> > 
> > 
> 
> > 
> > *
> > 
> > 
> > *hosts: "{{ hosts_group }}"
> > vars:
> > * dt_product_id: '{65E3C889-BF02-4A22-9E22-5DCA88789582}'
> > name: "dynatrace oneagent install on windows"
> > tasks:
> > 
> > |name: "validate ansible tower execution on windows" win_stat: path: 
> C:\Temp register: temp_dir |
> > 
> > o name: "check if oneagent is already installed via windows service 
> registry key"
> > win_reg_stat:
> > path: HKLM:\SYSTEM\CurrentControlSet\Services\Dynatrace OneAgent
> > name: DisplayName
> > register: installed
> > o name: "download oneagent install file"
> > win_get_url:
> > url: "{{ dt_api_endpoint 
> }}deployment/installer/agent/windows/default/latest?Api-Token={{ 
> dt_api_token
> > }}=x86=default"
> > dest: C:\Temp\dynatrace-oneagent-windows-latest.exe
> > o name: "install: execute oneagent install file"
> > win_package:
> > product_id: "{{ dt_product_id }}"
> > path: C:\Temp\dynatrace-oneagent-windows-latest.exe
> > arguments:
> > + HOST_GROUP="{{ dt_host_group }}"
> > + APP_LOG_CONTENT_ACCESS="{{ dt_app_log_content_access }}"
> > + INFRA_ONLY="{{ dt_infra_only }}"
> > state: present
> > when: installed.exists == False
> > o name: "update: validate existing oneagent product id exists"
> > win_reg_stat:
> > path: 
> "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ 
> dt_product_id }}"
> > name: DisplayName
> > register: uninstall
> > when: installed.exists == True
> > o name: "update: uninstall existing oneagent package"
> > win_package:
> > product_id: "{{ dt_product_id }}"
> > state: absent
> > when: installed.exists == True and uninstall.exists == True
> > o name: "update: execute oneagent install file"
> > win_package:
> > path: C:\Temp\dynatrace-oneagent-windows-latest.exe
> > product_id: "{{ dt_product_id }}"
> > arguments:
> > + HOST_GROUP="{{ dt_host_group }}"
> > + APP_LOG_CONTENT_ACCESS="{{ dt_app_log_content_access }}"
> > + INFRA_ONLY="{{ dt_infra_only }}"
> > state: present
> > when: installed.exists == True and uninstall.exists == True
> > 
> > -- 
> > 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-proje...@googlegroups.com  ansible-proje...@googlegroups.com>.
> > To view this discussion on the web visit
> > 
> https://groups.google.com/d/msgid/ansible-project/085b82df-bd65-406d-bb22-0efbd5bb3ec7%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/085b82df-bd65-406d-bb22-0efbd5bb3ec7%40googlegroups.com?utm_medium=email_source=footer
> >.
>
>
> -- 
> Ecommerce 

RE: [EXTERNAL] Re: [ansible-project] edit string in a multi-line file

2023-07-27 Thread 'Hearn, Stan J.' via Ansible Project
What you want to use is backrefs.

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html

An Example from the document:
# NOTE: Yaml requires escaping backslashes in double quotes but not in single 
quotes
- name: Ensure the JBoss memory settings are exactly as needed
  ansible.builtin.lineinfile:
path: /opt/jboss-as/bin/standalone.conf
regexp: '^(.*)Xms(\d+)m(.*)$'
line: '\1Xms${xms}m\3'
backrefs: yes

From: dulhaver via Ansible Project 
Sent: Thursday, July 27, 2023 10:12 AM
To: ansible-project@googlegroups.com
Subject: [EXTERNAL] Re: [ansible-project] edit string in a multi-line file


curious actually how this can be achieved with sophisticated regex and the 
lineinfile module


On 07/27/2023 4:08 PM CEST dulhaver via Ansible Project 
 wrote:


would this do what you want?


- name: edit a line in a file
  ansible.builtin.command:
chdir: /home/username/
cmd: 'sed -i "s/This is a file/This is a new file/" somefile'


On 07/27/2023 3:13 PM CEST Kathy L  wrote:


I am trying to edit a string in a multi-line file.  For instance, if I had this 
string:

This is a file and I am editing it
I want to add the string "new" in front of file if it does not exist already.

I've tried lineinfile, but the issue is that I don't know what else is on the 
line.  There could be more data after "This is a file and I am editing it" that 
I don't want to change.  What is the best way to do this?



--
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/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com.



--
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/910865649.32.1690466922457%40office.mailbox.org.
--
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/354691782.311307.1690467142008%40office.mailbox.org.

-- 
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/PH0PR10MB55935C5AAE6D641F829FEDEBF001A%40PH0PR10MB5593.namprd10.prod.outlook.com.


Re: [ansible-project] edit string in a multi-line file

2023-07-27 Thread Kathy Lyons
That will work - yes.  I was so focused on using lineinfile or another
ansible module, I forgot about sed.  Thank you!

On Thu, Jul 27, 2023 at 10:09 AM dulhaver via Ansible Project <
ansible-project@googlegroups.com> wrote:

> would this do what you want?
>
>
> - name: edit a line in a file
>   ansible.builtin.command:
> chdir: /home/username/
> cmd: 'sed -i "s/This is a file/This is a new file/" somefile'
>
>
>
> On 07/27/2023 3:13 PM CEST Kathy L  wrote:
>
>
> I am trying to edit a string in a multi-line file.  For instance, if I had
> this string:
>
> This is a file and I am editing it
>
> I want to add the string "new" in front of file *if* it does not exist
> already.
>
> I've tried lineinfile, but the issue is that I don't know what else is on
> the line.  There could be more data after "This is a file and I am editing
> it" that I don't want to change.  What is the best way to do this?
>
>
>
> --
> 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/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com
> .
>
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/yZgBhYf9B7Q/unsubscribe.
> To unsubscribe from this group and all its topics, 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/910865649.32.1690466922457%40office.mailbox.org
> 
> .
>

-- 
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/CAK9%2BsMfzcVAd8MwtvOhmL30UjqsMWtmv5gZujVm%2BVzk%2BqX%3Df0w%40mail.gmail.com.


Re: [ansible-project] edit string in a multi-line file

2023-07-27 Thread dulhaver via Ansible Project
 
curious actually how this can be achieved with sophisticated regex and the 
lineinfile module
 
 

> On 07/27/2023 4:08 PM CEST dulhaver via Ansible Project 
>  wrote:
>  
>  
> would this do what you want?
>  
>  
> - name: edit a line in a file
>   ansible.builtin.command:
> chdir: /home/username/
> cmd: 'sed -i "s/This is a file/This is a new file/" somefile'
>  
>  
> 
> > On 07/27/2023 3:13 PM CEST Kathy L  wrote:
> >  
> >  
> > I am trying to edit a string in a multi-line file.  For instance, if I had 
> > this string:
> > 
> > This is a file and I am editing it
> > 
> > I want to add the string "new" in front of file if it does not exist 
> > already.
> >  
> > I've tried lineinfile, but the issue is that I don't know what else is on 
> > the line.  There could be more data after "This is a file and I am editing 
> > it" that I don't want to change.  What is the best way to do this?
> > 
> > 
> > 
> >  
> > 
> > --
> > 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 
> > mailto:ansible-project+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/ansible-project/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com
> >  
> > https://groups.google.com/d/msgid/ansible-project/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%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 
> mailto:ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/910865649.32.1690466922457%40office.mailbox.org
>  
> https://groups.google.com/d/msgid/ansible-project/910865649.32.1690466922457%40office.mailbox.org?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/354691782.311307.1690467142008%40office.mailbox.org.


Re: [ansible-project] edit string in a multi-line file

2023-07-27 Thread dulhaver via Ansible Project
would this do what you want?
 
 
- name: edit a line in a file
  ansible.builtin.command:
chdir: /home/username/
cmd: 'sed -i "s/This is a file/This is a new file/" somefile'
 
 

> On 07/27/2023 3:13 PM CEST Kathy L  wrote:
>  
>  
> I am trying to edit a string in a multi-line file.  For instance, if I had 
> this string:
> 
> This is a file and I am editing it
> 
> I want to add the string "new" in front of file if it does not exist already.
>  
> I've tried lineinfile, but the issue is that I don't know what else is on the 
> line.  There could be more data after "This is a file and I am editing it" 
> that I don't want to change.  What is the best way to do this?
> 
> 
> 
>  
> 
> --
> 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 
> mailto:ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com
>  
> https://groups.google.com/d/msgid/ansible-project/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%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/910865649.32.1690466922457%40office.mailbox.org.


[ansible-project] edit string in a multi-line file

2023-07-27 Thread Kathy L
I am trying to edit a string in a multi-line file.  For instance, if I had 
this string:

This is a file and I am editing it

I want to add the string "new" in front of file *if* it does not exist 
already.

I've tried lineinfile, but the issue is that I don't know what else is on 
the line.  There could be more data after "This is a file and I am editing 
it" that I don't want to change.  What is the best way to do this?


-- 
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/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com.


Re: [ansible-project] escalation problem with 'copy' TASK

2023-07-27 Thread Will McDonald
 become and become_user: postgresis are at the wrong indentation level in
the task?

On Wed, 26 Jul 2023 at 15:53, dulhaver via Ansible Project <
ansible-project@googlegroups.com> wrote:

> I have a copy TASK
>
>
> ###
> - name: copy archive to "{{ postgres_install }}"
>   ansible.builtin.copy:
> src: "../temp/{{ item }}"
> dest: "/opt/db/postgres/install/{{ item }}"
> become: true
> become_user: postgres
> mode: 0644
> owner: postgres
> group: postgres
>   loop:
> - "postgresql-{{ pg_version }}-postgis-{{ gis_version
> }}-el8-ina1.tar.gz"
>
> ###
>
>
> but am getting a 'Failed to get information on remote file ... permission
> denied' from my remotes
>
>
> ###
>
> TASK [copy archive to "/opt/db/postgres/install"]
> ***
> task path:
> /home/gwagner/repos/automation_postgres/playbooks/pg_copy_archive_to_server.yml:38
>  ESTABLISH SSH CONNECTION FOR USER: None
>  SSH: EXEC ssh -C -o ControlMaster=auto -o
> ControlPersist=60s -o StrictHostKeyChecking=no -o
> KbdInteractiveAuthentication=no -o
> PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey
> -o PasswordAuthentication=no -o ConnectTimeout=10 -o
> 'ControlPath="/home/gwagner/.ansible/cp/9e44e07a70"'
> dvzsn-rd5095.portal.cn-mv.de '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
>  ESTABLISH SSH CONNECTION FOR USER: None
>  SSH: EXEC ssh -C -o ControlMaster=auto -o
> ControlPersist=60s -o StrictHostKeyChecking=no -o
> KbdInteractiveAuthentication=no -o
> PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey
> -o PasswordAuthentication=no -o ConnectTimeout=10 -o
> 'ControlPath="/home/gwagner/.ansible/cp/fabb7bb55e"'
> dvzsn-rd5097.portal.cn-mv.de '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
>  (0, b'/home/gwagner\n', b'')
>  ESTABLISH SSH CONNECTION FOR USER: None
>  SSH: EXEC ssh -C -o ControlMaster=auto -o
> ControlPersist=60s -o StrictHostKeyChecking=no -o
> KbdInteractiveAuthentication=no -o
> PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey
> -o PasswordAuthentication=no -o ConnectTimeout=10 -o
> 'ControlPath="/home/gwagner/.ansible/cp/9e44e07a70"'
> dvzsn-rd5095.portal.cn-mv.de '/bin/sh -c '"'"'( umask 77 && mkdir -p "`
> echo /home/gwagner/.ansible/tmp `"&& mkdir "` echo
> /home/gwagner/.ansible/tmp/ansible-tmp-1690382167.2929223-3916028-198146789170963
> `" && echo ansible-tmp-1690382167.2929223-3916028-198146789170963="` echo
> /home/gwagner/.ansible/tmp/ansible-tmp-1690382167.2929223-3916028-198146789170963
> `" ) && sleep 0'"'"''
>  (0, b'/home/gwagner\n', b'')
>  ESTABLISH SSH CONNECTION FOR USER: None
>  SSH: EXEC ssh -C -o ControlMaster=auto -o
> ControlPersist=60s -o StrictHostKeyChecking=no -o
> KbdInteractiveAuthentication=no -o
> PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey
> -o PasswordAuthentication=no -o ConnectTimeout=10 -o
> 'ControlPath="/home/gwagner/.ansible/cp/fabb7bb55e"'
> dvzsn-rd5097.portal.cn-mv.de '/bin/sh -c '"'"'( umask 77 && mkdir -p "`
> echo /home/gwagner/.ansible/tmp `"&& mkdir "` echo
> /home/gwagner/.ansible/tmp/ansible-tmp-1690382167.3025672-3916029-195671938319344
> `" && echo ansible-tmp-1690382167.3025672-3916029-195671938319344="` echo
> /home/gwagner/.ansible/tmp/ansible-tmp-1690382167.3025672-3916029-195671938319344
> `" ) && sleep 0'"'"''
>  (0,
> b'ansible-tmp-1690382167.3025672-3916029-195671938319344=/home/gwagner/.ansible/tmp/ansible-tmp-1690382167.3025672-3916029-195671938319344\n',
> b'')
>  (0,
> b'ansible-tmp-1690382167.2929223-3916028-198146789170963=/home/gwagner/.ansible/tmp/ansible-tmp-1690382167.2929223-3916028-198146789170963\n',
> b'')
> Using module file /usr/lib/python3.9/site-packages/ansible/modules/stat.py
> Pipelining is enabled.
>  ESTABLISH SSH CONNECTION FOR USER: None
> Using module file /usr/lib/python3.9/site-packages/ansible/modules/stat.py
> Pipelining is enabled.
>  SSH: EXEC ssh -C -o ControlMaster=auto -o
> ControlPersist=60s -o StrictHostKeyChecking=no -o
> KbdInteractiveAuthentication=no -o
> PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey
> -o PasswordAuthentication=no -o ConnectTimeout=10 -o
> 'ControlPath="/home/gwagner/.ansible/cp/9e44e07a70"'
> dvzsn-rd5095.portal.cn-mv.de '/bin/sh -c
> '"'"'/usr/libexec/platform-python && sleep 0'"'"''
>  ESTABLISH SSH CONNECTION FOR USER: None
>  SSH: EXEC ssh -C -o ControlMaster=auto -o
> ControlPersist=60s -o StrictHostKeyChecking=no -o
> KbdInteractiveAuthentication=no -o
> PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey
> -o PasswordAuthentication=no -o ConnectTimeout=10 -o
> 

Re: [ansible-project] escalation problem with 'copy' TASK

2023-07-27 Thread dulhaver via Ansible Project
thx for that suggestion, however I can do this without any problem
 
   ansible postgres -l @../temp/limit_agrar -m copy -a 
"src=../temp/postgresql-12.15-postgis-3.2.5-el8-ina1.tar.gz 
dest=/opt/db/postgres/install/ mode=0644 owner=postgres group=postgres" -b 
--become-user=postgres
 
and I'd say that has the same privilege situation as my playbook
 
 

> On 07/26/2023 6:03 PM CEST Dick Visser  wrote:
>  
>  
> 
> On Wed, 26 Jul 2023 at 16:53, dulhaver via Ansible Project 
> mailto:ansible-project@googlegroups.com> 
> wrote:
> 
> > ull 2>&1 && sleep 0'"'"''
> >  (0, b'', b'')
> > fatal: [http://dvzsn-rd5097.portal.cn-mv.de]: FAILED! => {
> > "msg": "Failed to get information on remote file 
> > (/opt/db/postgres/install/postgresql-14.8-postgis-3.3.3-el8-ina1.tar.gz): 
> > Permission denied"
> > }
> >  (0, b'', b'')
> > fatal: [http://dvzsn-rd5095.portal.cn-mv.de]: FAILED! => {
> > "msg": "Failed to get information on remote file 
> > (/opt/db/postgres/install/postgresql-14.8-postgis-3.3.3-el8-ina1.tar.gz): 
> > Permission denied"
> > }
> > ###
> > 
> > the permissions on that folder look good enough for the postgres user to 
> > write
> > 
> > > ls -l /opt/db/postgres/ | grep install
> > drwxr-x---. 2 postgres postgres  89 26. Jul 16:21 install
> > 
> > 
> > 
> > any idea what my problem may be?
> > 
>  
> Permissions after all. There is a dot at the end of your permissions, which 
> usually indicates that an SELinux context is present.
> I don't know how that exactly works.
> In any case is it not an ansible problem but a local permissions problem.
> So make sure that is fixed, and then your ansible task will work as well.
>  
>  
> 
>  
> 
> --
> 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 
> mailto:ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/CAF8BbLbbz02yK4J0LmkU9igX49LN2%2B%3D2EnsCm07f4qHj4W-RoQ%40mail.gmail.com
>  
> https://groups.google.com/d/msgid/ansible-project/CAF8BbLbbz02yK4J0LmkU9igX49LN2%2B%3D2EnsCm07f4qHj4W-RoQ%40mail.gmail.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/62133875.276327.1690440972836%40office.mailbox.org.