[ansible-project] Restart server playbook fails on one set of targets, but not on another.

2018-08-16 Thread Patrick Hunt
I have the following playbook snippet

---


- hosts: collector
  become: true
  become_method: su
  become_user: root


  tasks:


  - name: restart server, if kernel updated
command: reboot
async: 1
poll: 0
ignore_errors: true
notify:
  - wait for server to restart


  handlers:
  - name: wait for server to restart
wait_for:
  host: "{{ ansible_default_ipv4.address }}"
  port: 22
  state: started
  delay: 25
  timeout: 300
become: false
delegate_to: localhost


...



This is really part of a much larger maintenance playbook.  My problem is 
that in our Test environment (RHEL 6 & 7) this succeeds, in our Dev 
environment (CentOS 7) this fails.  When the play fails ansible will 
connect and gather facts, when the play to restart is executed it will 
state that the server is unreachable, however the task has been executed 
and the server *is* restarted if you check the actual VM.  It seems that 
the execution of the tasks completes before ansible is able to recognize 
this fact, so it never gets to the point where it waits for the server to 
restart and fails as unreachable instead.

The ansible.cfg files are identical.  The inventory (hosts) files do not 
have any additional variables/connection information other than hostnames 
and groups defined.

In the dev environment the playbook is executed as root, and in the Test 
environment the playbook is executed as a user.

Both environments are running ansible 2.6.2

The dev environment functioned properly for a year or more until about 2-3 
months ago when this restart task began to fail.

Any ideas?


Thanks, 
Patrick

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3db9e382-1842-4dc9-8b4c-284ba243a03f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Starting AppDynamics with play

2018-03-20 Thread Patrick Hunt
Good idea Kai, 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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0351c16e-5e86-439e-b212-7f51f7f3b93e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: git checkout to new branch and change back to local user

2018-03-13 Thread Patrick Hunt
Good catch.  You're correct, it is possible, I was mistaken.  Practically 
is it possible to be able to provide multiple sets of credentials for your 
example?  I've always done a work around, such as I listed in the other 
comment, since I can pass my current logon (-k) username/password, and can 
pass 1 set of become credentials (-K), but not a 2nd or 3rd set of become 
credentials.

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9dd70ae0-e2e6-4698-94dd-52c68c45901f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: git checkout to new branch and change back to local user

2018-03-13 Thread Patrick Hunt

>
> I can help to address #2 at least for now.
>

Ansible does not allow you to chain "Become" statements.  In other words 
you cannot log in as user1, become root, and then become user2 (or even 
user1) in the same play.  You could address this in a few different ways 
that I know of:

- split the play into multiple plays within a playbook where you can set 
the become for each different play:

---
- host: localhost
  become: true
  become_user: root
  become_method: su


  tasks:
  - name: some play performed as root


- host: localhost
  become: true
  become_user: user2
  become_method: su


  tasks:
  - name: some other play performed as user2

- host: localhost
  become: false

  tasks:
  - name: some other play performed as user1
...

- you could also use a command module workaround (at least with a Nix 
system) such as:

---
- hosts: localhost
  become: true
  become_user: root
  become_method: su


  tasks:
  - name: some task as root


  - name: some task as user2
command: su - user2 -c "/home/user2/somecommand.sh"
...


My follow-up question is... why?  In your example you could just create the 
file as root, set the owner, group, and mode to reflect the user you want 
it to be.

Hope this helps a bit.

Thanks, 
Patrick

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a3e6f37a-aaa6-439d-9ef0-2388c6e76e65%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Starting AppDynamics with play

2018-03-13 Thread Patrick Hunt
I used the "async" and "poll" options to work around this.  So my trouble 
task now looks like:

- name: start eum
shell: bin/eum.sh start
args:
  chdir: /opt/AppDynamics/EUEM/eum-processor/
async: 30
poll: 10



If I register the output as a variable and print it, it still only displays 
the "EUM Processor started..." line, but the EUM process is actually, as 
opposed to previously where it would not be fully started before the play 
ended.


Hope this helps someone else out!



On Tuesday, March 13, 2018 at 8:10:49 AM UTC-4, Patrick Hunt wrote:
>
> I have a play that is fairly simple, to start AppDynamics.  I am able to 
> start/stop each part as needed, except a portion called EUM (End User 
> Monitoring).
>
> My test play looks like:
>
> ---
> - hosts: collector
>   become: true
>   become_method: su
>   become_user: root
>
>
>   tasks:
>
>
>   - name: stop eum
> shell: bin/eum.sh stop
> args:
>   chdir: /opt/AppDynamics/EUEM/eum-processor/
>
>
>   - name: wait 2 minutes
> wait_for:
>   timeout: 120
> delegate_to: localhost
>
>
>   - name: start eum
> shell: bin/eum.sh start
> args:
>   chdir: /opt/AppDynamics/EUEM/eum-processor/
> ...
>
>
> The problem is with the "start eum" task.  The output from running the 
> playbook is:
>
> PLAYBOOK: restart_eum.yml 
> *
> 1 plays in restart_eum.yml
>
>
> PLAY [collector] 
> **
>
>
> TASK [Gathering Facts] 
> 
> ok: [eum-server]
> META: ran handlers
>
>
> TASK [stop eum] 
> ***
> task path: /home/phunt/ansible/test/playbooks/restart_eum.yml:9
> changed: [eum-server] => {"changed": true, "cmd": "bin/eum.sh stop", 
> "delta": "0:00:01.047571", "end": "2018-03-13 07:52:38.369432", "rc": 0, 
> "start": "2018-03-13 07:52:37.321861", "stderr": "", "stderr_lines": [], 
> "stdout": "EUM Processor stopped.", "stdout_lines": ["EUM Processor 
> stopped."]}
>
>
> TASK [wait 2 minutes] 
> *
> task path: /home/phunt/ansible/test/playbooks/restart_eum.yml:14
> ok: [eum-server -> localhost] => {"changed": false, "elapsed": 120, "path"
> : null, "port": null, "search_regex": null, "state": "started"}
>
>
> TASK [start eum] 
> **
> task path: /home/phunt/ansible/test/playbooks/restart_eum.yml:19
> changed: [eum-server] => {"changed": true, "cmd": "bin/eum.sh start", 
> "delta": "0:00:01.031939", "end": "2018-03-13 07:54:42.994837", "rc": 0, 
> "start": "2018-03-13 07:54:41.962898", "stderr": "", "stderr_lines": [], 
> "stdout": "EUM Processor started (PID=23232).", "stdout_lines": ["EUM 
> Processor started (PID=23232)."]}
> META: ran handlers
> META: ran handlers
>
>
> PLAY RECAP 
> 
> eum-server  : ok=4changed=2unreachable=0failed=0
>
>
>
> This indicates that the EUM processor has started, however, when I log 
> into the server EUM is not running.
>
> When entering the commands in manually to start eum there is an additional 
> line of output that is present 3-5 seconds after the "EUM Processor 
> started..." bit.  The output from manual run is:
&

Re: [ansible-project] Default shell behavior: Where are scripts executed? No such file or directory.

2018-03-13 Thread Patrick Hunt
Your subject line has a question in it, but the body does not.  Is your 
question "Where are scripts executed?"  If that is your question then yes, 
you're correct, it should be the home directory of the user you logged into 
the remote server with.  You can see by doing something like 


ansible servera -m shell -a "ls"-u username

This will print the contents of the working directory when a user logs in.  
Try it with the become options to see what the result is.  You can use an 
absolute path to call a script.  Or use the "chdir" option for shell, 
something like

---
- hosts: collector
  become: true
  become_method: su
  become_user: root


  tasks:


  - name: stop eum
shell: bin/eum.sh stop
args:
  chdir: /opt/AppDynamics/EUEM/eum-processor/



should guarantee that you're in the correct location.



On Monday, March 12, 2018 at 4:56:20 PM UTC-4, Brian Coca wrote:
>
> shell executes on the remote machine, it does not look for any 
> resources 'local' to the controller, the 'working directory' depends 
> on login/become setup used on the target machine (normally 
> /home/. 
>
> But this is only important for relative paths. 
>
> -- 
> -- 
> 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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/860341a5-a05c-4e94-8115-f037f8592c57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Starting AppDynamics with play

2018-03-13 Thread Patrick Hunt
I have a play that is fairly simple, to start AppDynamics.  I am able to 
start/stop each part as needed, except a portion called EUM (End User 
Monitoring).

My test play looks like:

---
- hosts: collector
  become: true
  become_method: su
  become_user: root


  tasks:


  - name: stop eum
shell: bin/eum.sh stop
args:
  chdir: /opt/AppDynamics/EUEM/eum-processor/


  - name: wait 2 minutes
wait_for:
  timeout: 120
delegate_to: localhost


  - name: start eum
shell: bin/eum.sh start
args:
  chdir: /opt/AppDynamics/EUEM/eum-processor/
...


The problem is with the "start eum" task.  The output from running the 
playbook is:

PLAYBOOK: restart_eum.yml 
*
1 plays in restart_eum.yml


PLAY [collector] 
**


TASK [Gathering Facts] 

ok: [eum-server]
META: ran handlers


TASK [stop eum] 
***
task path: /home/phunt/ansible/test/playbooks/restart_eum.yml:9
changed: [eum-server] => {"changed": true, "cmd": "bin/eum.sh stop", "delta"
: "0:00:01.047571", "end": "2018-03-13 07:52:38.369432", "rc": 0, "start": 
"2018-03-13 
07:52:37.321861", "stderr": "", "stderr_lines": [], "stdout": "EUM 
Processor stopped.", "stdout_lines": ["EUM Processor stopped."]}


TASK [wait 2 minutes] 
*
task path: /home/phunt/ansible/test/playbooks/restart_eum.yml:14
ok: [eum-server -> localhost] => {"changed": false, "elapsed": 120, "path": 
null, "port": null, "search_regex": null, "state": "started"}


TASK [start eum] 
**
task path: /home/phunt/ansible/test/playbooks/restart_eum.yml:19
changed: [eum-server] => {"changed": true, "cmd": "bin/eum.sh start", 
"delta": "0:00:01.031939", "end": "2018-03-13 07:54:42.994837", "rc": 0, 
"start": "2018-03-13 07:54:41.962898", "stderr": "", "stderr_lines": [], 
"stdout": "EUM Processor started (PID=23232).", "stdout_lines": ["EUM 
Processor started (PID=23232)."]}
META: ran handlers
META: ran handlers


PLAY RECAP 

eum-server  : ok=4changed=2unreachable=0failed=0



This indicates that the EUM processor has started, however, when I log into 
the server EUM is not running.

When entering the commands in manually to start eum there is an additional 
line of output that is present 3-5 seconds after the "EUM Processor 
started..." bit.  The output from manual run is:



[root@collector eum-processor]# bin/eum.sh start
Using EUM_HOME:   /opt/AppDynamics/EUEM/eum-processor
Using EUM_PID:pid.txt
EUM Processor started (PID=23595).
[root@collector eum-processor]# INFO  [2018-03-13 12:02:05,136] 
org.eclipse.jetty.util.log: Logging initialized @2571ms


Is there a way for me to wait for that INFO line before marking the task as 
completed?


Thank you, 
Patrick

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a712b8e2-7353-4179-826e-49783efd4aa0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: vmware_guest_snapshot module unable to find VM with Ansible 2.4.2

2018-01-31 Thread Patrick Hunt
I was able to use another module to solve this issue.  I setup a play using 
the module vmware_guest_find 
.

The play I used is:

- hosts: localhost
  vars_prompt:
- name: username
  prompt: "VCenter username"
  private: no


- name: password
  prompt: "VCenter password"
  private: yes


  tasks:
  - name: find vm paths
vmware_guest_find:
  hostname: vcenter.host
  datacenter: QAE
  name: "{{ item }}"
  password: "{{ password }}"
  username: "{{ username }}"
  validate_certs: false
register: path
deligate_to: localhost
with_items:
  - vm1.domain
  - vm2.domain
  - vm3.domain
  - vm4.domain
...



The output (with the verbosity increased -vv) is:
ok: [localhost] => (item=vm1.domain) => {"changed": false, "folders": 
["/vm/Staging"], "item": "vm1.domain"}


So this gave me the path of /vm/Staging.  Per the module documentation for 
vmware_guest_snapshot 
 it 
is stated that the datacenter should also be included in the folder.  So 
the value for folder, in my example, is "QAE/vm/Staging" and now my 
snapshot playbooks work.


I hope this is able to help someone else.

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4d02eca5-2387-4427-a7af-7689e03b1eef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] vmware_guest_snapshot module unable to find VM with Ansible 2.4.2

2018-01-30 Thread Patrick Hunt
I have recently updated to Ansible 2.4.2

I have plays that will remove old snapshots from specific VMs and will 
create new snapshots for those VMs.  

The remove playbook is as follows:

---
- hosts: localhost
  vars_prompt:
- name: username
  prompt: "VCenter username"
  private: no


- name: password
  prompt: "VCenter password"
  private: yes


  tasks:


  - name: Remove Staging snapshots
vmware_guest_snapshot:
  validate_certs: false
  datacenter: QAE
  hostname: vcenter.host
  username: "{{ username }}"
  password: "{{ password }}"
  name: "{{ item }}"
  state: remove_all
  folder: /Staging/
delegate_to: localhost
with_items:
  - vm1.domain
  - vm2.domain
  - vm3.domain
  - vm4.domain
...

Since the update to 2.4.x these playbooks have stopped working.

Looking at the Ansible module documentation I see the following change for 
vmware_guest_snaphsot 
:


folder
no /vm 
Destination folder, absolute or relative path to find an existing guest.
This is required if name is supplied.
The folder should include the datacenter. ESX's datacenter is ha-datacenter
Examples:
folder: /ha-datacenter/vm
folder: ha-datacenter/vm
folder: /datacenter1/vm
folder: datacenter1/vm
folder: /datacenter1/vm/folder1
folder: datacenter1/vm/folder1
folder: /folder1/datacenter1/vm
folder: folder1/datacenter1/vm
folder: /folder1/datacenter1/vm/folder2
folder: vm/folder2
folder: folder2


Our datacenter is "QAE" and one of the folders I want to interact with is 
"Staging".  I have tried updating the "folder: /Staging/" to folder: 
/QAE/Staging/, QAE/Staging/, QAE/Staging, /QAE/Staging and each time this 
fails with the error:

"failed: [localhost -> localhost] (item=vm1.domain) => {"changed": false, 
"item": "vm1.domain", "msg": "Unable to manage snapshots for non-existing 
VM vm1.domain"}

This exact playbook worked in 2.3.x as shown above.  Is anyone else using 
this module and has overcome this issue?  

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2f465a8f-b2ab-4904-a8fe-c2936c740c23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.