Re: [ansible-project] Re: don't print statement if "command not found" and compare variable value with list of values

2018-11-16 Thread Dan Linder
Correction to my previous email:
You *COULD* run a play right before it that registers the full path of
`systemctl` found on the system (maybe use `shell: which systemctl`), but
that is not a stable method in some cases.  I suggest using `systemd:` with
the OS version check if needed.

On Fri, Nov 16, 2018 at 9:31 PM  wrote:

> I'd suggest not using the `shell:` module, instead use the `systemd:`
> module.
>
> Then setup the `when:` clause with a third that only executes this play on
> OS versions that have `systemctl` (e.g. RHEL 7+, etc).  You run a play
> right before it that registers the full path of `systemctl` found on the
> system (maybe use `shell: which systemctl`).
>
> Something like this:
>  - name: manage services using systemctl
>tags:  manage services using systemctl
>systemd:
>  name: {{servicesList}}
>  state: {{actionTodo}}
>with_items:
>  - "{{servicesList}}"
>when:
>  - ansible_os_family == "RedHat" and ansible_lsb.major_release|int
> >= 7
>  - actionTodo != ""
>  - servicesList != ""
>ignore_errors: true
>register: p2
>
>
> On Friday, November 16, 2018 at 8:06:40 AM UTC-6, moisset...@gmail.com
> wrote:
>>
>> i'm trying this in a playbook:
>>
>> ..
>> vars:
>>actionTodo: "{{ variable_actionTodo }}"
>>servicesList: "{{ variable_servicesList }}"
>>actionTodo_list: [start,stop,rstart,rstop,status,rstatus]
>> ..
>>
>>  - name: manage services using systemctl
>> tags:  manage services using systemctl
>> shell:  systemctl {{actionTodo}} {{servicesList}}
>> with_items:
>>   - "{{servicesList}}"
>> when: actionTodo != "" and  servicesList != ""
>> ignore_errors: true
>> register: p2
>>
>>
>>   - debug:
>>   var: p2
>>
>> i'd like to compare:
>> - actionTo value with value from actionTo_list
>> - and avoid printing "command not found"  node without systemctl
>>
>>
>> --
> 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/JLS67ALa3AU/unsubscribe.
> To unsubscribe from this group and all its topics, 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/b662b375-3856-4da9-8af4-c449285db436%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
* * *** *** * *** **
"If you wish to make an apple pie from scratch,
  you must first invent the universe."
  -- Carl Sagan

"Quis custodiet ipsos custodes?"
(Who can watch the watchmen?)
-- from the Satires of Juvenal

"I do not fear computers, I fear the lack of them."
-- Isaac Asimov (Author)
** *** * *** *** * *

-- 
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/CAGYusaNHuQc%2B7DoL6_7-MFk1uf_ZRvhePwnLX%3DAoGLjCpK9H2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: don't print statement if "command not found" and compare variable value with list of values

2018-11-16 Thread dan
I'd suggest not using the `shell:` module, instead use the `systemd:` 
module.

Then setup the `when:` clause with a third that only executes this play on 
OS versions that have `systemctl` (e.g. RHEL 7+, etc).  You run a play 
right before it that registers the full path of `systemctl` found on the 
system (maybe use `shell: which systemctl`).

Something like this:
 - name: manage services using systemctl
   tags:  manage services using systemctl
   systemd: 
 name: {{servicesList}}
 state: {{actionTodo}}
   with_items:
 - "{{servicesList}}"
   when:
 - ansible_os_family == "RedHat" and ansible_lsb.major_release|int 
>= 7
 - actionTodo != ""
 - servicesList != ""
   ignore_errors: true
   register: p2


On Friday, November 16, 2018 at 8:06:40 AM UTC-6, moisset...@gmail.com 
wrote:
>
> i'm trying this in a playbook:
>
> ..
> vars:
>actionTodo: "{{ variable_actionTodo }}"
>servicesList: "{{ variable_servicesList }}"
>actionTodo_list: [start,stop,rstart,rstop,status,rstatus]
> ..
>
>  - name: manage services using systemctl
> tags:  manage services using systemctl
> shell:  systemctl {{actionTodo}} {{servicesList}}
> with_items:
>   - "{{servicesList}}"
> when: actionTodo != "" and  servicesList != ""
> ignore_errors: true
> register: p2
>
>
>   - debug:
>   var: p2
>
> i'd like to compare:
> - actionTo value with value from actionTo_list
> - and avoid printing "command not found"  node without systemctl 
>
>
>

-- 
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/b662b375-3856-4da9-8af4-c449285db436%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Installing WinRM offline

2018-11-16 Thread Dick Visser
On Fri, 16 Nov 2018 at 23:45, Kartik Jayaraman  wrote:

> Hello,
>
> I have a Centos VM which is cut off from the internet. It does have
> Ansible installed but does not have pywinrm installed. It did not even have
> pip installed.
>
> So I installed pip offline, basically downloaded the tar.gz and copied to
> the VM using WinSCP. After which i installed using "python setup.py
> install" command
>
> I tried doing the same of pywinrm-0.3.0, but there are way too many
> dependencies for ntlm etc that the installation aborts, because it looks to
> go to the web and does not find.
>
> So right now i am stuck where my small little playbook throws this error.
> Please can someone assist? Thanks in advance
>

You will either have to repeat this for every dependency you come across,
or address your inability to access the internet.
It depends on your local situation which option is the shortest path to
success.

Dick
-- 
Sent from a mobile device - please excuse the brevity, spelling and
punctuation.

-- 
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/CAL8fbwOAk2ySVa0Nst24r34aJvw%3DRUZPGhK%2BKUnT5CCZ%3DmtpVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Installing WinRM offline

2018-11-16 Thread Kartik Jayaraman
Hello,

I have a Centos VM which is cut off from the internet. It does have Ansible 
installed but does not have pywinrm installed. It did not even have pip 
installed.

So I installed pip offline, basically downloaded the tar.gz and copied to 
the VM using WinSCP. After which i installed using "python setup.py 
install" command

I tried doing the same of pywinrm-0.3.0, but there are way too many 
dependencies for ntlm etc that the installation aborts, because it looks to 
go to the web and does not find.

So right now i am stuck where my small little playbook throws this error. 
Please can someone assist? Thanks in advance

ansible web -i inventory.yml -m win_ping

10.xxx.xxx.xx | FAILED! => {
"msg": "winrm or requests is not installed: No module named winrm"
}


Thanks in advance for your assistance

-- 
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/08621152-27bd-4e7a-8d6a-7b70d24481ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] ANSIBLE PERMISSIONS

2018-11-16 Thread Brian Coca
Not all modules are wrappers to shell commands, specifically this
module is not using any commands, its using python code and system
calls, which you cannot create sudo entries for.




-- 
--
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/CACVha7crgEQU4yRtPVLW3w4%3DDZBO7tukyjBb8Dxe6Fv4dOSE4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] ANSIBLE PERMISSIONS

2018-11-16 Thread fahad . riaz1718
I wrote a playbook that allows a local user to use ansible "LINEINFILE" 
module to edit /etc/sssd/sssd.conf and /etc/fstab. However I gave that 
local user to run all sudo commands without password. 

I want to limit the local user and only give specific permissions in the 
/etc/sudoers file. . I want to know what LINUX command is actually being 
used when we run LINEINFILE OR INSERTALINEINFILE ansible module.

an example of my playbook is as follows. 

- name: Editing sssd.conf file
lineinfile:
  path: /etc/sssd/sssd.conf
  line: sudo_provider = ldap


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/37df9e2b-1dda-4437-9f49-c82d3843ae14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] ansible-pull minimal standalone version

2018-11-16 Thread Brian Coca
ansible-pull uses ansbile and ansible-playbook under the hood, so the
ansible package IS the minmal package available

you might want to trim modules/plugins you don't use but that depends
on the plays being executed.



-- 
--
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/CACVha7cVZu1J0PkwJXd97c12iOnUYzTYs4ZMULN11mKy%2BpBzJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] subversion export issue

2018-11-16 Thread Dick Visser
It doesn't get any clearer that this.
Your svn repo is probably an HTTPS one, but you're using a hostname
that isn't in the certificate.
Hence, svn will bail out.


Dick
On Fri, 16 Nov 2018 at 13:48,  wrote:
>
> Hi All,
>
> I am trying to export subversion repo using ansible-playbook.
>
> ---
> - hosts: remoteserver
>   tasks:
>   - name: "checkout subversion repo "
> subversion:
>  repo=
>  dest=/abc/xyz/subdir
>  force=yes
>  export=yes
>  username={{ subversion_username }}
>  password={{ subversion_password }}
>
>
> ran the playbook
> ansible-playbook subversion.yml --ask-vault-pass
>
>
> Error message:
>
> Vault password:
>
> PLAY [remoteserver] 
> *
>
> TASK [Gathering Facts] 
> **
> ok: [abc.com]
>
> TASK [checkout subversion repo] 
> *
> fatal: [abc.com]: FAILED! => {"changed": false, "cmd": "/usr/bin/svn 
> --non-interactive --trust-server-cert --no-auth-cache --username '' 
> --password '' export --force -r HEAD  /abc/xyz/subdir", 
> "msg": "svn: E175002: Unable to connect to a repository at URL 
> ''\nsvn: E175002: OPTIONS of '': Server certificate 
> verification failed: certificate issued for a different hostname, issuer is 
> not trusted ()", "rc": 1, "stderr": "svn: E175002: Unable to 
> connect to a repository at URL ''\nsvn: E175002: OPTIONS of 
> '': Server certificate verification failed: certificate issued for 
> a different hostname, issuer is not trusted ()\n", "stderr_lines": 
> ["svn: E175002: Unable to connect to a repository at URL ''", "svn: 
> E175002: OPTIONS of '': Server certificate verification failed: 
> certificate issued for a different hostname, issuer is not trusted 
> ()"], "stdout": "", "stdout_lines": []}
>
> PLAY RECAP 
> **
> abc.com : ok=1changed=0unreachable=0failed=1
>
>
>
> --
> 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/ae8d742c-459f-48d6-9a64-38b8a2891c0d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAL8fbwOrJyaNmFRyEKdRiHxXykb_jDZ-NwswQdLKG%3DNAsmwSCg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] don't print statement if "command not found" and compare variable value with list of values

2018-11-16 Thread moissetgerard0
i'm trying this in a playbook:

..
vars:
   actionTodo: "{{ variable_actionTodo }}"
   servicesList: "{{ variable_servicesList }}"
   actionTodo_list: [start,stop,rstart,rstop,status,rstatus]
..

 - name: manage services using systemctl
tags:  manage services using systemctl
shell:  systemctl {{actionTodo}} {{servicesList}}
with_items:
  - "{{servicesList}}"
when: actionTodo != "" and  servicesList != ""
ignore_errors: true
register: p2


  - debug:
  var: p2

i'd like to compare:
- actionTo value with value from actionTo_list
- and avoid printing "command not found"  node without systemctl 


-- 
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/ebce1f66-f537-46dd-a810-9b9c64728f3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] subversion export issue

2018-11-16 Thread rajendra . rawat17
Hi All,

I am trying to export subversion repo using ansible-playbook.

---
- hosts: remoteserver
  tasks:
  - name: "checkout subversion repo "
subversion:
 repo=
 dest=/abc/xyz/subdir
 force=yes
 export=yes
 username={{ subversion_username }}
 password={{ subversion_password }}


ran the playbook
ansible-playbook subversion.yml --ask-vault-pass


Error message:

Vault password:

PLAY [remoteserver] 
*

TASK [Gathering Facts] 
**
ok: [abc.com]

TASK [checkout subversion repo] 
*
fatal: [abc.com]: FAILED! => {"changed": false, "cmd": "/usr/bin/svn 
--non-interactive --trust-server-cert --no-auth-cache --username '' 
--password '' export --force -r HEAD  /abc/xyz/subdir", 
"msg": "svn: E175002: Unable to connect to a repository at URL 
''\nsvn: E175002: OPTIONS of '': Server certificate 
verification failed: certificate issued for a different hostname, issuer is 
not trusted ()", "rc": 1, "stderr": "svn: E175002: Unable to 
connect to a repository at URL ''\nsvn: E175002: OPTIONS of 
'': Server certificate verification failed: certificate issued 
for a different hostname, issuer is not trusted ()\n", 
"stderr_lines": ["svn: E175002: Unable to connect to a repository at URL 
''", "svn: E175002: OPTIONS of '': Server certificate 
verification failed: certificate issued for a different hostname, issuer is 
not trusted ()"], "stdout": "", "stdout_lines": []}

PLAY RECAP 
**
abc.com : ok=1changed=0unreachable=0failed=1



-- 
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/ae8d742c-459f-48d6-9a64-38b8a2891c0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'"}

2018-11-16 Thread 'Stephen C.' via Ansible Project
Hi Tom, 

Can you try a couple of options and post it to this thread please ? 
With the same inventory file: 

[mysql] 
  mysql01 
  mysql02 
  mysql03 
  mysql04



ansible-playbook -i infra --limit mysql02 main.yml --tags "mysql" -v

ansible-playbook -i infra --limit mysql03 main.yml --tags "mysql" -v


Thnx, 
Stephen

On Wednesday, November 14, 2018 at 9:15:38 AM UTC-5, Kai Stian Olstad wrote:
>
> On 14.11.2018 14:49, Tom K. wrote: 
> > On Tuesday, November 13, 2018 at 3:10:18 AM UTC-5, Tom K. wrote: 
> > 
> > Ok.  So I removed a couple of tags from the mysql task "mysql : Copy 
> > my.cnf 
> > global MySQL configuration."  and adjusted the play as follows: 
>
> The playbook is fine, the problem is the limit option your are using on 
> ansible-playbook. 
>
>
> > [root@awx01 ansible]# vi main.yml 
> > --- 
> > - name: Gather all facts prior to execution 
> >   hosts: mysql 
> >   gather_facts: true 
> >   tasks: 
> > - debug: msg='{{ inventory_hostname }} has default IP {{ 
> > ansible_default_ipv4["address"] }}' 
> > - template: 
> > src: test.j2 
> > dest: /tmp/test.out 
> >   tags: mysql 
> > 
> > 
> > - name: Install and configure MySQL 
> >   hosts: mysql 
> >   become: true 
> >   roles: 
> > - mysql 
> >   tags: mysql 
> > 
> > 
> > But that didn't work.  Still got the original error with mysql04.   
> > Until I 
> > removed mysql01-3 from the infra file leaving only mysql04: 
> > 
> > [mysql] 
> > mysql04 
> > 
> > 
> > And reran using: 
> > 
> > ansible-playbook -i infra --limit mysql04 main.yml --tags "mysql" -v 
>
>
> You still have the same problem I commented on earlier. 
>
> When you run a with --limit, the task and *gather_facts* is only run on 
> host specified in the limit. 
> So when you in you template try using facts for mysql01-03 they don't 
> exist since you haven't gather them so you get the error message. 
>
> So remove you --limit and it will work, the template you have will never 
> work if you specify limit. 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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/fcb52497-8ebf-419a-b017-4347e978d0e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Get "Could not find the requested service" when trying to restart httpd; but it is installed

2018-11-16 Thread Dick Davies
Could not find the requested service ['httpd']: host"}

looks to me like your issue is in the playbook., You're passing an
array ( 'services' ) in as the service name, ansible is treating that
as a length 1 array
rather than just a string. Replace the "{{ services }}" with just :
httpd and I bet it works.
On Thu, 15 Nov 2018 at 13:17, Sean Hederman  wrote:
>
> The pid file is at
>
> /var/run/httpd/httpd.pid
>
>
> How would I check where the stop script expects it to be?
>
>
> On Thursday, November 15, 2018 at 10:47:47 AM UTC, Karl Auer wrote:
>>
>> This is almost certainly to do with the PID file.
>>
>> Check that it is where the stop script expects it to be.
>>
>> Regards, K.
>>
>>
>> On Thu, Nov 15, 2018 at 9:44 PM Sean Hederman  wrote:
>>>
>>> - name: Restart Apache
>>> service:
>>> name: "{{ services }}"
>>> state: restarted
>>> enabled: yes
>>> become: true
>>> vars:
>>> services:
>>> - httpd
>>>
>>> Have tried variants with different states, enabled, become. All fail with 
>>> exact same error:
>>> amzn-build: TASK [web_server : Restart Apache] 
>>> * amzn-build: fatal: 
>>> [127.0.0.1]: FAILED! => {"changed": false, "msg": "Could not find the 
>>> requested service ['httpd']: host"}
>>>
>>> Logging onto the instance and running:
>>>
>>> sudo service httpd restart
>>>
>>> Stopping httpd:[FAILED]
>>>
>>> Starting httpd:[  OK  ]
>>>
>>>
>>> Vanilla Amazon 2018.03 image with ansible installed via pip
>>>
>>> I cannot see why ansible would report that httpd does not exist when it 
>>> patently does
>>>
>>> --
>>> 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.
>>> To post to this group, send email to ansible...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/ansible-project/99d478d2-10a7-449a-b573-b3a83e308232%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> Karl Auer
>>
>> Email  : ka...@2pisoftware.com
>> Website: http://2pisoftware.com
>>
>> GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
>> Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA
>
> --
> 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/fb53b56c-a863-4538-93f0-00d7a6a63ffd%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAK5eLPRDiRUeHfWmnr1qfCLqjNYK2NKMLX0Yu0iTRatL7PAwMA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] how to use systemd to start my custom service

2018-11-16 Thread Dick Davies
 "msg": "Failed to get D-Bus connection: Operation not permitted",

you're not running ansible with high enough privileges. try a become:
yes somewhere in there.
On Thu, 15 Nov 2018 at 02:47, Ronnie10  wrote:
>
> Hi all,
>
> I am trying to setup zookeeper using ansible with docker, I have copied the 
> zookeeper.service to /usr/lib/systemd/system, however when I run molecule 
> test to test my ansible code, it always fail.
>
> My zookeeper.service looks like following:
> [Unit]
> Requires=network.target remote-fs.target
> After=network.target remote-fs.target
>
> [Service]
> Type=simple
> #User=kafka
> ExecStart=/opt/kafka_2.11-2.0.0/bin/zookeeper-server-start.sh 
> /opt/kafka_2.11-2.0.0/config/zookeeper.properties
> ExecStop=/opt/kafka_2.11-2.0.0/bin/zookeeper-server-stop.sh
> Restart=on-abnormal
>
> [Install]
> WantedBy=multi-user.target
>
>
> My ansible script as follow:
> ---
> - name: Check if Zookeeper service file exists
>   stat:
> path: /usr/lib/systemd/system/zookeeper.service
>   register: zookeeper_service_exist
>
> - name: Copy zookeeper service file to /usr/lib/systemd/system/
>   copy:
> src: files/zookeeper.service
> dest: /usr/lib/systemd/system/
> mode: 0755
>   when: not zookeeper_service_exist.stat.exists
>
> - name: Start Zookeeper service if not started
>   systemd:
> name: zookeeper
> state: started
>
> I always receive the following error:
>fatal: [kafka-deploy]: FAILED! => {
> "changed": false,
> "cmd": "/bin/systemctl",
> "invocation": {
> "module_args": {
> "daemon_reload": false,
> "enabled": null,
> "force": null,
> "masked": null,
> "name": "zookeeper",
> "no_block": false,
> "scope": null,
> "state": "started",
> "user": null
> }
> },
> "msg": "Failed to get D-Bus connection: Operation not permitted",
> "rc": 1,
> "stderr": "Failed to get D-Bus connection: Operation not permitted\n",
> "stderr_lines": [
> "Failed to get D-Bus connection: Operation not permitted"
> ],
> "stdout": "",
> "stdout_lines": []
> }
>
> Hope someone can help me with 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 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/f26fab5c-e7c7-4ebd-a5af-b46a012cb211%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAK5eLPRAZvnkRYWZS0HWfdS-bP%2B%2BizeSpXoxiKK5wM_-R_CF6g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Parallel execution of tasks in playbook

2018-11-16 Thread 'J Hawkesworth' via Ansible Project
Hello,

Ansible will run tasks in parallel against groups of hosts, so I suggest 
you convert your 

apache_sever_list.yaml

file into ansible inventory format

and put all the hosts in it into a group called 'apache'

then you can run tasks against

- hosts: apache
  tasks:
  - name: any tasks here run against all the hosts in apache group 
simultaneously


What its nice is you can still use 'delegate_to: localhost' for your uri 
task and it will still run the task from the ansible controller (but run it 
in parallel for each host in your 'apache' group).

Also, have a look at 'template' module I think you will find it a lot 
easier to create the html file than the combination of shell commands and 
lineinfile.  

I don't have time to test this today but try experimenting with organising 
things as follows:

Create an inventory file for your apache hosts:

# file: apache_hosts 
# this is an ansible inventory file (using 'ini' format but can use yaml)
# see 
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html for 
more about inventory 
[apache]
host1 ap_port=8081
host2 ap_port=80
host3 ap_port=8080
host4 ap_port=8008
host5 ap_port=8123

Create a template file like this:

# ansible template file: apache.html.j2
# see 
https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts
# for how to use variables in templates.


List of failed Apache servers

HostnamePort
<%for host_result in apache_check_result %>
{{ examine apache_check_result to find hostname from results }}{{ again use apache_check_result to get at the port used | default('Failed' 
}}




Create a playbook like this:

# playbook: apache_check.yml

- name: report on apache status 
  gather_facts: yes
  hosts: apache
  
  tasks:
- name: Check the apache server status
  uri:
url: "{{ ansible_hostname }}:{{ ap_port }}"
method: GET
status_code: 200
body_format: raw
follow_redirects: all
return_content: yes
validate_certs: no
force: yes
  register: apache_check_result
  ignore_errors: yes
  delegate_to: localhost  
  
- name: show results for debugging purposes
  debug:
 var: apache_check_result
  
- name: template out the results
  template:
src: apache_html.j2
dest: /var/apache.html
  delegate_to: localhost
 

  and run the playbook like this

ansible-playbook -i apache_hosts apache_check.yml


Sorry I haven't got time to debug this but I hope the above will illustrate 
that by using ansible's inventory you can get your tasks to run in parallel 
(and also that using the 'template' module is a great way to create files 
from ansible.

Hope this helps get you on the right track.

All the best,

Jon






On Thursday, November 15, 2018 at 3:40:34 PM UTC, Build Admin wrote:
>
> Thank you for your reply.
> I tried using strategy as free and unable to use async in the task as task 
> has dependency task. Could you please suggest code change or alternate 
> method for running the task in parallel.
>
> ---
> - name: Main playbook
>   gather_facts: no
>   hosts: 127.0.0.1
>   strategy: free
>
>   tasks:
> - name: Create csv file and html file
>   file:
> path: "{{ item }}"
> state: touch
>   delegae_to: localhost
>   become_user: awx
>   become: no
>   with_items:
> - /tmp/apache.csv
> - /tmp/apache.html
>
> - include_vars: apache_sever_list.yaml
>
> - include_tasks: apache_task.yaml
>   with_items: '{{ apacheSevers }}'
>
> - name: Run the csv2html script
>   shell: |
> echo "List of failed Apache servers"
> echo "" ;
> echo "HostnamePort"
> while read INPUT; do
> echo "${INPUT//,/}";
> done < /tmp/apache.csv
> echo ""
>   delegae_to: localhost
>   become_user: awx
>   become: no
>
> - name: append
>   lineinfile:
> dest: /tmp/apache.html
> line: "{{ output.stdout }}"
> insertafter: EOF
>   delegae_to: localhost
>   become_user: awx
>   become: no
>
>
>
> *apche_task.yaml*
>
> - name: Check the apache server status
>   uri:
> url: "{{ item.hostname }}:{{ item.port }}"
> method: GET
> status_code: 200
> body_format: raw
> follow_redirects: all
> return_content: yes
> validate_certs: no
> force: yes
>   delegae_to: localhost
>   become_user: awx
>   become: no
>
>
> - name: append output to file
>   lineinfile:
> dest: /tmp/apache.csv
> line: "{{ item.hostname }},{{ item.port }}"
> insertafter: EOF
>   delegae_to: localhost
>   become_user: awx
>   become: no 
>
>
>
>
> On Wednesday, November 14, 2018 at 9:07:18 AM UTC-5, Brian Coca wrote:
>>
>> I would look at the 'free' strategy, but you have others: 
>>